Tuesday, March 8, 2011

Get Your SAS On or ... Get Your SAS in Gear

Rules for SAS

SAS statements end with a semicolon ; - just like in C#
Case does not matter unlike C#
Continuation is allowed, don't split words though

Some Sample SAS

This lil' procedure produces a report that displays the values of the variables in the SAS data set WEIGHT_CLUB

proc print data=weight_club;
title 'Health Club Data';
run;

The first line, the print procedure, tells the program to display the variables in a simple, organized form. The title slaps a title on the top of the report and run ... well .... that runs the program.

Here is the sample output:

Health Club Data Obs Id Number Name Team Start Weight End Weight Loss 1 1023 David Duke red 189 179 10 2 1049 Dan Quayle yellow 155 144 11 3 1219 Ronnie Reagan red 171 170 1

In order to do some calculations, you need to use the TABULATE procedure.

Proc means procedure.

proc tabulate data=weight_club;
class team;
var StartWeight EndWeight Loss;
table team, mean*(StartWeight EndWeight Loss);
title 'Mean Starting Weight, Ending Weight,';
title2 'and Weight Loss';
run;

And the results ...

MeanStartWeight EndWeight LossTeamred175.33158.3317yellow169.5150.519


You can see that a class, team is declared in this procedure and three variables; StartWeight, EndWeight and Loss.

Notice how it is not necessary to put commas between the variable names.

The next statement performs the mean, or average) calculation ... mean*( StartWeight EndWeight Loss)

Finally, we get some more titles and the run statement.





No comments:

Post a Comment