SAS Program basics

A SAS program is a sequence of steps that the user submits for execution. In SAS programming, user should create DATA step (source) and PROC step (Analyse the data).

In Statistical Analysis System (SAS), there are two types of SAS statements :

  1. SAS statements used in DATA Step and PROC step.
  2. Global statements (can be used anywhere in a SAS program).

A SAS Statement is a type of SAS language element (or) a string of SAS keywords, SAS names, special characters and operations that instructs SAS to perform specific operations like ABORT, CALL, CONTINUE, DELETE, DO, DECLARE and so on.

  • SAS statements are free-format which means statement can begin and end anywhere on aline.
  • A SAS statement can be specified in uppercase and lowercase letters
  • SAS statements starts with SAS keyword and should ended with semicolon.

DATA Step

A data step is that which creates or modifies data using input data types like raw data or a SAS data set. Output from a Data step will be Data set or a report.

  • Data step inserts data into a SAS data set.
  • It computes values and check for correct errors.

PROC Step

PROC means Procedure step, it analyses input data like SAS data set and produces output such as reports or an updated data set.

  • PROC Step creates reports.
  • Creates summary reports.
  • Produces plots and charts.

Global Statements

Global statements are the one used anywhere in a SAS program. Global statements takes effect until it is changed, canceled or SAS session ends.

How SAS reads the data into variables?

Whenever space comes in the data values or upto 8 char length in data values, whichever comes first will read to into variable.

Terminology :

TechnicalData WarehousingSQLSAS
FileTableTableData set
FieldPortColumnVariable
RecordRowRow / RecordObservation
  • Tables are called datasets
  • Columns are called variables.
  • Rows are called observations.
SAS statement - SAS program basics

The values of a particular variable may be missing for some observations in that case missing character data represented as blanks and missing numeric data represented by period (.)

Example:- TITLE, LIBNAME, OPTIONS, FOOTNOTE.

An example SAS program that contain DATA step and PROC step is given below :

data sasuser.admit2;
set sasuser.admit2; 
where age>25;
run;
proc print data=sasuser.admit2;
run;

Note :  As shown in above SAS program, it contains DATA Step which starts with DATA statement (data sasuser.admit2) to produce new SAS data set only for an age value greater than 25. SET statement(set sasuser.admit2) reads an observation from SAS data sets, RUN statement executes the statements, PROC print statement produces printed report.

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         data sasuser.admits2;
 74            set sasuser.admit2;
 75            where age>25;
 76            run;
 
 NOTE: There were 19 observations read from the data set SASUSER.ADMIT2.
       WHERE age>25;
 NOTE: The data set SASUSER.ADMITS2 has 19 observations and 9 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 77            proc print data=sasuser.admit2;
 78            run;
 
 NOTE: There were 19 observations read from the data set SASUSER.ADMIT2.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.15 seconds
       cpu time            0.12 seconds
       
 
 79         
 80         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 93

SAS program Result SAS Statement