SAS Program Structure – Steps Involved in a SAS Program

In our last SAS Programming tutorial, we have seen SAS user interface and today we will talk about SAS program structure, steps involved in program structure of SAS Programming: SAS data step, PROC Step in SAS. Lastly, we will see some basic differences between SAS DATA and SAS PROC in brief.

Let’s now begin with the structure of SAS Program.

Structure of SAS Program

Stay updated with the latest technology trends while you're on the move - Join DataFlair's Telegram Channel

1. SAS Program Structure

Before you run an analysis, write a report, before you do anything with your data, SAS must be able to read your data. For data to be analyzed by SAS, it first has to be in the form of a dataset. SAS DataSet is the organization of data values in a table in the form of rows and columns. The main components of a SAS program are the DATA step and the PROC step.

Below is a diagrammatical representation of steps involved in the structure of the SAS Program.

 SAS Program Structure

Steps Involved – SAS Program Structure

Here, is a simple program that converts kilometers to meters inside a SAS DATA step and prints the results in a SAS PROC step:

DATA distance;
kilometers = 23; <=====   DATA STEP
meters = 1000*kilometers;
PROC PRINT DATA = distance;
Run;  <======  PROC STEP

SAS Program Structure

Let us examine each SAS component in detail.

i. SAS DATA Step

This step involves loading the required data set into SAS memory.

A DATA step reads and modifies data and starts with the keyword DATA. This keyword is followed by a name that you make up for a SAS data set. The DATA step above produces a SAS data set named DISTANCE.

The SAS DATA Step is used for the following purposes:

  • Getting input data into a SAS dataset.
  • Editing- checking for any errors in the data and correcting them.
  • Creating new SAS data sets from existing ones by merging and updating the old data sets.
  • Data manipulation such as updating, modifying or rearranging data in a SAS dataset.

Syntax:

DATA data_set_name;                #Name of the data set.
INPUT var1,var2,var3;                #Defines the variables in this data set.
NEW_VAR;                                 #Creates a new variable.
LABEL;                                       #Assign labels to variables.
DATALINES;                                #Enters the data.
RUN;

ii. SAS PROC Step

The beginning of all procedures in SAS starts with a PROC statement in which the keyword PROC is followed by the name of the procedure (MOD, PRINT, Proc SORT, or Proc MEANS, for example). In this step, a SAS built-in procedure is invoked for analyzing the data. Just like the recipe is followed in a sequential manner, in SAS we use basically the same statements every time.

Syntax:

PROC procedure_name options;   #The name of the proc.
RUN;

iii. SAS OUTPUT  Step

An end of a step occurs when SAS comes across a new step which is marked by a DATA or PROC statement and a RUN statement. RUN statements tell SAS to run all the preceding lines. RUN statements, however, are not part of a DATA or PROC step.

In the SAS program above, SAS comes to know that the SAS DATA step has ended when it comes to the PROC statement in the next line. The PROC step ends with a RUN statement, which means the program has ended.

3. Difference Between DATA Step and PROC Step

Here, are some basic differences between SAS DATA Step and PROC steps in SAS:

DATA step 

PROC step

They always Begin with DATA statements They always begin with PROC statements
Read and modify data Perform specific analysis on data
Create a SAS data setProduce results or report

4. Summary

Hence, although a typical SAS program starts with a SAS DATA step to input data and then passes that data to a PROC step in SAS, it is not a hard and fast rule. Like you can stack building blocks in any order, you can arrange DATA and PROC steps in any order. The SAS program has the flexibility to contain either only DATA steps or only PROC steps.

Furthermore, if you have any query, feel free to ask in the comment section.

Crack your SAS interview by practicing SAS interview questions

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.