1. SAS environment:

When you open windows version SAS (Click Start -> Program -> The SAS System -> The SAS System for Windows V9). You will see something like:

 

So as you can see, basically SAS version 9 contains five windows: Enhanced Program Editor, Log, Output, Explorer, and Results manager.

Program Editor window: Allow you to put codes there. If you prefer seeing the line number, key in "num on" in the command entry (near top left corner)

Log window: Whenever you submit codes, it will automatically shows messages about the submission, whether is is successfully submitted, what has been created, or the syntax error one made. It help you about testing/debugging your SAS codes.

Output window: List-formated output. It automatically adds system title, date, and running page number on the header.

Explorer window: Like explorer in MS windows, You can browse all the libraries (like folders) along with its members (like files). The difference is we only can see SAS related files here which include dataset, catalog, view, ... etc.

Results manager window: After your submitting, you will see the categorized output including procedure results, graph output. That provides a flexible tool to edit and manage your outputs.

2. How does SAS work?

First thing to know is that SAS is not an interactive programming tool (same thing for C, Fortran). The working mechanism for SAS is: Editor (entering codes)---> SAS engine (checking syntax error, if not compiling your codes into executive format, then followed by execution) ---> Display your results (in Log and Output windows).

Unlike R, S+ (both using S language) and MATLAB, SAS doesn't provides prompt-typed interactive execution. Instead, you have to ASSEMBLE SAS statements to get what you want. I would call it a project-oriented software. Which means it is designed to help you deal with whole project, not simple calculation like "1+1" kind of stuff.

I called it assembling codes instead of programming (term mostly used in comp. languages), because it needs special treatments in order to do the programming control.

3. Syntax Structure:

Basically, you need at least two sections: DATA STEP, and PROCEDURE STEP.  A SAS program consists of several data steps and procedures. Explain them separately in the following.

SAS is case insensitive (whatever your input case is, SAS will recode them in upper ). But I will use bold upper case to denote system keywordsplain upper case to denote syntax for corresponding steps, italic lower case for customized input, and statement within parenthesis for optional use. Each complete statement ends with semi-colon ";". Each line can contain several statements. I personally prefer to put just one statement in a line for convenience of debugging. On the other hand, a command can cross several lines.

DATA dataset-name;

  INPUT variable-names-formats (options);

DATALINES;

data values.........................

;

RUN;

¡@

Ex:

DATA test;

  INPUT name $ y;

DATALINES;

Janet  1

Tom    2

John   3

;

RUN;

PROC procedure-name (DATA=datasetname options);

procedure-specific statement(s)...................;

RUN;

Ex:

PROC PRINT DATA= test;

RUN;

Note: if you don't specify dataset name in procedure, SAS will automatically refer to the latest generated dataset. So it is recommended that you specify the dataset name each time.

So, you have a idea about how to create a valid SAS program structure.