/*Kaz's SAS juku*/
/*www.estat.us*/
/*PROC SQL to create mean variables*/
Data ABC;
set sashelp.Prdsale; /*This is a SAS default data set for a practice*/
run;
/*note: This creates mean variables and then append them all nicely to the original data set.
Unlike PROC MEANS' way of creating mean variables, the units of anlaysis stay the same, which means
that the mean variables are just append to the original data sets. So if the mean for, say, groupA is 3.5
then all cases in groupA will receive 3.5. If you do proc means to get mean data, then you will be only
getting cases that are group level, which makes you merge the mean data back to the original data.
That would be too tedious when PROC SQL can do it just quickly.*/
proc sql;
create table newdata as
select *,
mean(actual) as newvariable_meanACTUEL,
mean(predict) as newvariable_meanPREDICT,
STD(actual) as newvariable_STDACTUEL,
STD(predict) as newvariable_STDPREDICT,
MAX(actual) as newvariable_MAXACTUEL,
MAX(predict) as newvariable_MAXPREDICT
from ABC
group by country;
run;
proc print data=newdata;
run;