SAS (Base SAS)+
data CLASS;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
;;;;
run;
data CLASS1;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
Henry|M|14|63.5|102.5
James|M|12|57.3|83
;;;;
run;
proc freq data=class;
tables sex/out=counts01;
run;
proc freq data=class1;
tables sex*age/out=counts02;
run;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
;;;;
run;
data CLASS1;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
Henry|M|14|63.5|102.5
James|M|12|57.3|83
;;;;
run;
proc freq data=class;
tables sex/out=counts01;
run;
proc freq data=class1;
tables sex*age/out=counts02;
run;
- To get frequency counts in SAS, we call
proc freqand list the variables to count in atablesstatement. proc freq data=class; tables sex / out=counts01;requests a one-way count of Sex on CLASS and writes the table to COUNTS01.- The
out=option is what turns the on-screen table into a dataset we can join, print, or export downstream. - For a cross tabulation, join variables with
*:tables sex*age / out=counts02;. - Each output dataset carries a COUNT column and a PERCENT column by default; the category variables appear on the left.
- After running, open COUNTS01 and COUNTS02 and confirm the totals match the input row counts.