Software developers or even academic students who are interested in learning more about SAS coding should take a look at some code fragments. More statistical data analysis information could, in theory, be gleaned from these than honestly anything else. While reading documentation and article exposition is nice, people might actually be able to learn a little more from studying examples than working with all of this auxiliary material.

## Code Fragments for the System

Let’s pretend that there’s a reason to write SAS codes that has to do with a study about students. There’s a secondary school that has 4,000 students in three different grade levels. Someone wants to find out how total household income and the number of children in a household influences average weekly spending on snacks. A sample is drawn from a random number of people in the student population. Pretend, for instance, that 40 students were surveyed since this is a clean percentage of the previous 4,000 individuals.

An array would be created as thus:

data IceCream;

input Grade Spending Income Students @@; datalines;

This would be followed by a chart of the data collected from the 40 aforementioned students, and finish off with ; and run;.

OLS regression is a nice technique to work with this sample, but it doesn’t necessarily acount for the sampling scheme in question:

title1 'Snacks Spending Analysis'; title2 'OLS Regression estimates'; data reg; set Snacks; if students=1 then do; s1= 1;s2= 0;s3= 0; end; if students=2 then do; s1= 0;s2= 1;s3= 0; end; if students=3 then do; s1= 0;s2= 0;s3= 1; end; if students=4 then do; s1= 0;s2= 0;s3= 0; end; run; proc reg data=reg; model Spending = Income s1--s3; run;

This is all well and good, but assume that grade is going to be a stratification variable, then some more research would need to be done on this sampling too:

proc surveyreg data=Snacks total=StudentTotal; strata Grade /list; class Students; model Spending = Income Students / solution; run;

Keep in mind that if there were more than one stratification variable in question that this study would have be done on more than one occasion for each variable, and the formula might change dependent on what said variable is.

## Putting it Together

The field of SAS coding as well as coding standards in С will change considerably depending on what type of study is being carried out. Some studies will need to be more sophisticated than others, and certain types will be rather complex all things considered. This translates into a situation where some code can be reused, which is a good thing. Keep in mind that some examples or even previously developed code could be used simply by changing out some of the variable names associated with it. This isn’t the most elegant way to reuse code in this respect, but it works.

For any statistical data analysis help contact us anytime.