Skip to main content

SAS: SAS 1 Workshop Materials

SAS 1: Introduction to SAS

Data for Workshop 1

age child ichild class degree housing cappun mari gun happy

47           2              3              3              3              1              1              1              1              2

61           2              0              2              4              1              1              1              1              2

72           1              2              2              3              1              1              2              1              1

43           1              4              2              3              1              1              1              2              2

55           2              2              1              3              1              1              1              1              1

53           2              2              2              3              2              1              1              1              1

50           1              2              3              3              1              1              2              1              2

23           2              3              2              2              1              1              2              1              1

45           3              3              2              1              1              2              2              1              2

71           1              4              3              3              2              1              2              1              2

33           2              5              4              3              1              2              1              1              3

86           2              4              3              3              1              1              2              1              3

32           2              3              3              2              1              2              1              1              1

60           2              5              2              3              1              1              1              1              1

76           1              7              2              3              2              2              2              2              2

33           1              2              3              2              1              2              1              1              2

56           1              6              1              2              1              2              1              1              1

62           2              5              2              1              2              2              1              2              2

31           2              0              2              2              1              2              1              2              2

43           2              2              3              1              1              2              1              1              2

58           1              0              3              3              1              1              1              2              2

32           1              3              2              2              2              2              1              2              2

23           1              2              2              2              2              2              2              1              1

37           1              2              3              2              1              2              1              1              1

25           1              2              4              2              2              2              2              1              2

76           2              8              4              2              1              2              2              1              3

71           1              2              3              3              2              1              1              1              1

22           2              0              3              3              1              2              1              2              3

74           1              2              2              4              2              1              2              2              2

75           1              3              1              3              1              2              1              1              3

Handout

Code

***** PULLING IN DATA;

DATA sas1;

INPUT age child ichild class degree housing cappun mari gun happy

 ;

DATALINES;

47           2              3              3              3              1              1              1              1              2

61           2              0              2              4              1              1              1              1              2

72           1              2              2              3              1              1              2              1              1

43           1              4              2              3              1              1              1              2              2

55           2              2              1              3              1              1              1              1              1

53           2              2              2              3              2              1              1              1              1

50           1              2              3              3              1              1              2              1              2

23           2              3              2              2              1              1              2              1              1

45           3              3              2              1              1              2              2              1              2

71           1              4              3              3              2              1              2              1              2

33           2              5              4              3              1              2              1              1              3

86           2              4              3              3              1              1              2              1              3

32           2              3              3              2              1              2              1              1              1

60           2              5              2              3              1              1              1              1              1

76           1              7              2              3              2              2              2              2              2

33           1              2              3              2              1              2              1              1              2

56           1              6              1              2              1              2              1              1              1

62           2              5              2              1              2              2              1              2              2

31           2              0              2              2              1              2              1              2              2

43           2              2              3              1              1              2              1              1              2

58           1              0              3              3              1              1              1              2              2

32           1              3              2              2              2              2              1              2              2

23           1              2              2              2              2              2              2              1              1

37           1              2              3              2              1              2              1              1              1

25           1              2              4              2              2              2              2              1              2

76           2              8              4              2              1              2              2              1              3

71           1              2              3              3              2              1              1              1              1

22           2              0              3              3              1              2              1              2              3

74           1              2              2              4              2              1              2              2              2

75           1              3              1              3              1              2              1              1              3

;

RUN;

 

***** EXPLANATION PULLING IN DATA;

** DATA dataname;

** INPUT var1 var2 var3 var4 var5 var6 var7 var8 var9 var10;

** var1res1         var2res1               var3res1               …             var10res1

** var1res2         var2res2               var3res2               …             var10res2

** var1res3         var2res3               var3res3               …             var10res3

** var1res4         var2res4               var3res4               …             var10res4

** …

** var1res10      var2res10            var3res10            …             var10res10

 

** ;

** RUN;

 

***** VIEW DATA IN A TABLE;

PROC PRINT DATA=sas1(obs=10);

RUN;

 

PROC PRINT DATA=sas1(obs=30);

RUN;

 

***** EXPLANATION VIEW DATA IN A TABLE;

** PROC PRINT DATA=dataname(obs=#);

**           RUN;

 

** PROC PRINT DATA= dataname (obs=#);

**           RUN;

 

***** FREQUENCY TABLES OPTION 1 (INDIVIDUAL COMMANDS);

PROC FREQ DATA=sas1;

TABLES age;

RUN;

 

PROC FREQ DATA=sas1;

TABLES child;

RUN;

 

PROC FREQ DATA=sas1;

TABLES ichild;

RUN;

 

***** EXPLANATION FREQUENCY TABLES OPTION 1 (INDIVIDUAL COMMANDS);

** PROC FREQ DATA= dataname;

**           TABLES var1;

**           RUN;

 

** PROC FREQ DATA= dataname;

**           TABLES var2;

**           RUN;

 

** PROC FREQ DATA= dataname;

**           TABLES var3;

**           RUN;

 

***** FREQUENCY TABLES OPTION 2 (ONE COMMAND);

PROC FREQ DATA=sas1;

TABLES age child ichild;

RUN;

 

***** EXPLANATION FREQUENCY TABLES OPTION 2 (ONE COMMAND);

** PROC FREQ DATA= dataname;

**           TABLES var1 var2 var3;

**           RUN;

 

 

***** DESCRIPTIVE STATISTICS OVERALL;

PROC MEANS DATA=sas1;

RUN;

 

***** EXPLANATION DESCRIPTIVE STATISTICS OVERALL;

** PROC MEANS DATA= dataname;

**           RUN;

 

***** DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CATEGORICAL;

PROC MEANS DATA=sas1;

                CLASS cappun;

RUN;

 

***** EXPLANATION DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CATEGORICAL;

** PROC MEANS DATA= dataname;

**           CLASS var1;

**           RUN;

 

***** DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CONTINUOUS ;

** PROC UNIVARIATE DATA= sas1;

**           VAR age;

**           RUN;

 

***** EXPLANATION DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CONTINUOUS ;

** PROC UNIVARIATE DATA= dataname;

**           VAR var1;

**           RUN;

 

***** DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CONTINUOUS BY EACH VALUE;

PROC FREQ DATA=sas1;

                TABLES child;

RUN;

 

***** EXPLANATION DESCRIPTIVE STATISTICS BY A SPECIFIC VARIABLE THAT IS CONTINUOUS BY EACH VALUE;

** PROC FREQ DATA= dataname;

**           TABLES var1;

**           RUN;

 

***** CROSSTABULATION;

PROC FREQ DATA=sas1;

                TABLES mari * gun;

RUN;

 

***** EXPLANATION CROSSTABULATION;

** PROC FREQ DATA= dataname;

**           TABLES var1 * var2;

**           RUN;

 

 

***** CROSSTABULATION WITHOUT SPECIFIC COMPONENTS (ORDER DOESN'T MATTER);

PROC FREQ DATA=sas1;

TABLES mari * gun / NOROW NOCOL NOFREQ;

RUN;

 

***** EXPLANATION CROSSTABULATION WITHOUT SPECIFIC COMPONENTS (ORDER DOESN'T MATTER);

** PROC FREQ DATA= dataname;

**           TABLES var1 * var2 / NOROW NOCOL NOFREQ;

**           RUN;

** NOTE: NOROW= no row percentages, NOCOL= no column percentages, NOFREQ= no frequencies per cell so the above code just gives percent’s per cell

 

***** BAR CHART;

TITLE 'Bar Chart for Ideal Number of Children;

PROC GCHART DATA=sas1;

VBAR ichild/ DISCRETE;

RUN;

 

***** EXPLANATION BAR CHART;

** TITLE 'Name for Bar Chart’;

**           PROC GCHART DATA= dataname;

**           VBAR var1/ DISCRETE;

**           RUN;

 

 

***** CORRELATION;

PROC CORR DATA = sas1 ;

                VAR ichild child age;

RUN;

 

***** EXPLANATION CORRELATION;

** PROC CORR DATA = dataname;

**           VAR var1 var2 var3;

**           RUN;

 

 

***** REGRESSION;

PROC REG DATA = sas1;

                MODEL ichild = child age housing happy;

RUN;

 

***** EXPLANATION REGRESSION;

** PROC REG DATA = dataname;

**           MODEL dependentvar = independentvar1 independentvar2 independentvar3 independentvar4;

**           RUN;

 

 

***** ANALYSIS OF VARIANCE;

PROC GLM DATA=sas1;

                CLASS gun;

                MODEL age = gun;

RUN; 

 

***** EXPLANATION ANALYSIS OF VARIANCE;

** PROC GLM DATA= dataname;

**           CLASS var1;

**           MODEL var2 = var1;

**           RUN;