/**************************************
This command file is for Exercise 4:
Summarizing Data.
filename: Exercise4_key.sas
***************************************/
OPTIONS FORMCHAR="|----|+|---+=|-/\<>*";
/*Define libnames for the data (SASDATA2)
and for the formats (LIBRARY)*/
libname sasdata2 "c:\users\kwelch\desktop\sasdata2";
libname library "c:\users\kwelch\desktop\sasdata2";
/*Proc Contents*/
proc contents data=sasdata2.hsb1 varnum;
run;
/*Sort data by school*/
proc sort data=sasdata2.hsb1;
by school;
run;
/*Calculate summary statistics byschool*/
proc means data=sasdata2.hsb1 noprint;
by school;
output out=meandat
n(school) = total /*total number in school*/
mean(SES) = mean_ses /*mean ses in school*/
mean(mathach) = mean_mathach /*mean math achieve. in school*/
sum(female) = tot_female /*total number of females in school*/
sum(minority) = tot_minority /*total number of minorities in school*/;
run;
/*Print the summary data set*/
proc print data=meandat(obs=10);
run;
/*Calculate percent female (PCT_FEMALE)
and percent minority (PCT_MINORITY) in each school*/
data meandat2;
set meandat;
pct_female = (tot_female/total)*100;
pct_minority = (tot_minority / total)*100;
format pct_female pct_minority 10.2;
run;
/*Descriptives for all variables*/
proc means data=meandat2;
run;
/*Frequencies for PCT_FEMALE and PCT_MINORITY*/
proc freq data=meandat2;
tables pct_female pct_minority;
run;
/*histogram for PCT_FEMALE and PCT_MINORITY*/
proc univariate data=meandat2;
var pct_female pct_minority;
histogram;
run;
/*Fit a regression line to predict MEAN_MATHACH based on
MEAN_SES */
ods graphics on;
proc reg data=meandat2;
model mean_mathach= mean_ses;
run;