My First SAS Program


SAS, Statistical Analysis Software is a software tool used to implement different statistical techniques and analysis on large data. SAS is one of the market leader in analysis tools industry. Its some of the major features include wide range of function library, results acceptability & data security.
This page will introduce you to the SAS coding &guide you through various aspects of sas coding.
I will keep on updating this page, with new functions time to time.

Let's begin & open your SAS window.
Courtesy: SAS institute, this edition is for education purpose only.

Once you click on SAS software icon, a window displayed as above will open. This window consist of three major sub-windows.

Program Editor Window: A SAS User write all programming codes in this window.

Log Window: In this section, a log of all your program compile or run stage errors, warning are displayed. It is imperative for a user to understand these errors & make changes to the program accordingly.

Explorer window: This acts as a navigation for user to move from one folder to other. All the dataset, formats & macros are saved in libraries. One can go to these libraries folder by navigation window & explore them.

Output window:  All program outputs are seen in this window. There are many configuration options to optimise the output results of any procedure.

My First SAS program:

Lets write a simple code for a Class-V student program. This data consist of Student ID, Height, Weight, Gender, Grades.

Every SAS program starts with a data step or a proc step.
A data step is used while creating, editing or sub-setting a dataset.

While a proc step is a procedure applied to a dataset.  This procedure can invoke a function like calculating mean of data, creating a cross tabulation, analysis of data.

Since we are creating a dataset, we will begin with datastep.

DATA CLASS5;
INPUT ID GENDER$ HEIGHT WEIGHT GRADES$;
DATALINES;
1 Male 78 33 C
2 Female 78 31 A+
3 Female 103 35 C
4 Female 71 37 C
5 Female 84 28 A
6 Male 104 34 C
7 Male 85 30 B+
...
..
.
57 Female 105 44 A+
58 Male 88 39 B+
59 Male 83 43 A
60 Male 77 28 C
;
RUN;

PROC PRINT DATA = CLASS5;
VAR HEIGHT WEIGHT;
RUN;

This is the right time to introduce the rules of naming of a variable or a dataset.
1, A variable or dataset name should not start with a number, underscore ( _ ) character.
2. Length of a name can not be more than 32 characters.
3. Spaces or dashes are not allowed.

Names like Class5, ID, Gender, Height, Weight, Grades are all valid names & can be used in SAS programming.
Class5 is a dataset name & that's why mentioned in the DATA step.

SAS has simplified datatypes by classifying into 2 categories.

First, Numeric, which represent data consisting of numbers. Here in our dataset we have height & weight as two numeric variable. The storage length in SAS is 8 bytes.

Character type data consist of letter, special characters, & numbers. In order to tell SAS that this is a character type variable name we have to place a dollar sign '$' after variable name.The storage length is 32 bytes

DATALINES is a keyword which tells SAS that lines following are of data, which are already declared in INPUT statement.

RUN statement is mentioned in the end of every SAS program. In its absence SAS keep on running & searching for a RUN statement.

Pic: 2 Showing Dataset CLASS5



PROC PRINT is a procedure statement that prints an output in Output window. Here we are generating a simple output of all the variables. Below is the output of the program.

Pic:3 Showing Output on Output window

No comments:

Post a Comment

My First SAS Program