*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c03s1d1.sas ***;
dm "output;clear;log;clear";
Libname Course2 "Y:\SasCourse2005\Course2\SAS_Data";
/*Create an accumulating variable with the RETAIN statement*/
data mnthtot;
set Course2.daysales;
retain Mth2Dte 0;
Mth2Dte=Mth2Dte+SaleAmt;
run;
proc print data=mnthtot noobs;
format SaleDate date9.;
title 'Calculate Sales to Date with the '
'RETAIN Statement';
run;
/*Create an accumulating variable with the sum statement*/
data mnthtot2;
set Course2.daysales;
Mth2Dte+SaleAmt;
run;
proc print data=mnthtot2 noobs;
format SaleDate date9.;
title 'Calculate Sales to Date with the '
'Sum Statement';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c03s2d1.sas ***;
dm "output;clear;log;clear";
Libname Course2 "C:\_SasCourse2006\Course2\SAS_Data";
/*Sort data set to prepare to summarize*/
proc sort data=Course2.empsals out=salsort;
by Div;
run;
proc print data=Course2.empsals; run;
proc print data=salsort; run;
/*Summarize Salaries by Division*/
data divsals(keep=Div DivSal);
set SalSort;
by Div;
if First.Div then DivSal=0;
DivSal+Salary;
if Last.Div;
run;
proc print data=divsals noobs;
title 'Employee Salaries by Division';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c03s2d2.sas ***;
dm "output;clear;log;clear";
/*Sort data set to prepare to summarize*/
proc sort data=Course2.regsals out=regsort;
by Region Div;
run;
proc print data=Course2.regsals; run;
proc print data=regsort; run;
/*Summarize Salaries by Division*/
data regdivsals(keep= Region Div DivSal NumEmps);
set RegSort;
by Region Div;
if First.Div then do;
DivSal=0;
NumEmps=0;
end;
DivSal+Salary;
NumEmps+1;
if Last.Div;
run;
proc print data=regdivsals noobs;
title 'Employee Salaries by Region and Division';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c02s3d01 ***;
dm "output;clear;log;clear";
Libname Course2 "C:\_SasCourse2006\Course2\SAS_Data";
proc contents data=Course2.military;
run;
data army navy airforce marines;
drop Type;
set Course2.military;
if Type eq 'Army' then
output army;
else if Type eq 'Naval' then
output navy;
else if Type eq 'Air Force' then
output airforce;
else if Type eq 'Marine' then
output marines;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c02s3d02 ***;
dm "output;clear;log;clear";
Libname Course2 "C:\_SasCourse2006\Course2\SAS_Data";
data army(drop=City State Country Type)
navy(drop=Type)
airforce(drop=Code Type)
marines;
set Course2.military;
if Type eq 'Army' then
output army;
else if Type eq 'Naval' then
output navy;
else if Type eq 'Air Force' then
output airforce;
else if Type eq 'Marine' then
output marines;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c02s3d03 ***;
dm "output;clear;log;clear";
Libname Course2 "C:\_SasCourse2006\Course2\SAS_Data";
data army(keep=Code Airport)
navy(keep=Code Airport City State Country)
airforce(keep=Airport City State Country)
marines;
set Course2.military;
if Type eq 'Army' then
output army;
else if Type eq 'Naval' then
output navy;
else if Type eq 'Air Force' then
output airforce;
else if Type eq 'Marine' then
output marines;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c02s3d04 ***;
data army(keep=Code Airport);
set Course2.military(drop=City State Country);
if Type eq 'Army' then output;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c02s3d05 ***;
data army;
set Course2.military(firstobs=11 obs=25);
if Type eq 'Army' then output;
run;