OVERVIEW OF SAS RULES

This section provides a systematic summary of some of the features you have seen in the examples up to now.

SAS Syntax

The primary features of SAS syntax are --

Data Step/Proc Step

SAS is divided into two distinct types of operations, called a data step and a proc step --

Here is an example of a small SAS program containing both a data step and a proc step --

income example

Note the use of indentation to structure the data step and the proc step.

Procedures cannot read raw data; only data steps read raw data. Data steps normally read data from some source (here the file named income.data) and write out a SAS data set (here called inc).

A built-in looping is performed in the data step. SAS reads a case, executes any instructions included in the data step, writes one case to the SAS data set, then returns to the beginning of the data step to repeat all instructions for the next case. This looping continues until all cases are read.
 

Files Used with SAS

Files serve five functions for SAS. The five types of files and their functions are listed below. When using interactive SAS (with the DMS), various windows substitute for the files. You must explicitly save the contents of a window to turn it into a file. The name of the window corresponding to each file is listed in parenthesis after the "usual extension."

Unless you explitly instruct otherwise, SAS creates a SAS data set each time a data step is run. If you do not provide for a permanent SAS data set, a temporary one is created and deleted at the end of the SAS session --

 * Create a temporary SAS dataset. SAS assigns the name *;

  data;

 * Create a temporary SAS data set named work.xyz.
   It may be referred to by xyz or by work.xyz *;

  data xyz; /* Creates a temporary SAS data set named work.xyz */

 * Create permanent SAS dataset. It must be referred to with
   its two-part name.

   The name of the unix file to be created/overwritten in this example
   is thesis.sas7bdat.  It will be stored in the current working
   directory, because of the period in the libname statement. *;

  libname thesis '.'; /* Period refers to current working dir */
  data thesis.earnings;

 * Execute a data step without producing any SAS dataset *;

  data _null_;

When saving the contents of a window, use the file extension corresponding to the window given in this list. Doing so helps you keep track of the contents of your files. Example: always save the contents of the program editor with a .sas extension. Save the contents of the saslog with a .log extension. And, save the contents of the output window with a .lst extension.