Basics of a SAS Program
The following is a basic example of a SAS program. The program goes through the following steps.
- Creates a Dataset
- Defines the columns (commonly referred to as variables in SAS)
- Reads inline values to populate the SAS dataset with
- Prints a basic report displaying all values in the dataset
- Prints output given the mean of 2 numeric variables specified
If you are new to SAS but familiar with SQL, then as you learn SAS it will be easier if you think of SAS Datasets as Tables and Variables as Columns.
Below is the sample program. Underneath that is the program with comments. Either of these programs can be copied and pasted into SAS and run with no other modification.
Simple SAS program example
DATA EMP_DATA;
INPUT EID : $5. F_NAME $ L_NAME $ AGE YRS_EMP;
CARDS;
15486 Mike Peters 41 8
52527 Louis Henna 52 14
54946 Sam Bass 31 4
17854 Cesar Chavez 25 7
77747 Fyodor Roosevelt 30 5
;
PROC PRINT DATA=EMP_DATA;
PROC MEANS MEAN; VAR AGE YRS_EMP;
Simple SAS program example with comments
/* This statement will tells SAS to create a dataset named EMP_DATA */
DATA EMP_DATA;
/* This statement describes how the data will be organized in the dataset */
INPUT EID : $5. F_NAME $ L_NAME $ AGE YRS_EMP;
/* CARDS as opposed to INFILE gives SAS the values to populate the dataset with */
CARDS;
15486 Mike Peters 41 8
52527 Louis Henna 52 14
54946 Sam Bass 31 4
17854 Cesar Chavez 25 7
77747 Fyodor Roosevelt 30 5
;
/* PROC PRINT gives tell SAS to print a report showing all values in the dataset */
PROC PRINT DATA=EMP_DATA;
/* PROC MEANS, in this example gives us the mean AGE and YRS_EMP (Years Employed) */
PROC MEANS MEAN; VAR AGE YRS_EMP;