Overview of SAS® programs
Why use SAS programs vs. SAS Insight or SAS Analyst?
- More flexible
- More powerful
- More dynamic
- Faster for programs used repeatedly
SAS Programs: Data steps and Proc steps (Section 1.3)
SAS programs are made up of a collection of data steps, proc steps and "open code."
Open code is simply special code that does not require being in data or proc step. Examples include the run,
quit and options statements and some macro statements.
- Both data and proc steps are made up of programming statements.
- In general, the statements used in a data step are different than those used in a proc step,
though there are some exceptions.
- Data steps
—read and modify data.
- Proc steps
—mostly act upon the data: analyze data, print reports of the data and
create graphic displays of data. Examples: PROC MEANS, PROC PRINT, PROC GLM, and PROC GPLOT.
- Data steps begin with the keyword DATA, and proc steps begin with the keyword PROC.
- Both data and proc steps end when SAS encounters a new step (data or proc) or a run statement.
Programming statements (Basic rules) (Section 1.1)
- Every statement ends with a semicolon!!
- SAS is case insensitive.
- Statements can continue over more than one line.
- More than one statement can be on a single line (separated by a semicolon).
- Statements can start in any column (with a few exceptions).
- A statement beginning with an asterisk is a comment.
- SAS ignores extra spaces. (So use spaces and comments to make programs more readable.)
Executing a SAS program (Section 1.5)
- Interactive SAS--start SAS and read/type in code and submit. See the results in the SAS windows.
- Batch SAS--the code executes without actually opening up the SAS windows. Output and log are saved into separate files. Should not do graphics with this method unless you channel the graphics output to a file.
SAS Windows (interactive SAS) (Section 1.6)
There are 4 main windows in SAS: Program editor, log, output and graphics windows. In addition, vsn. 7+ has a results and an explorer window and vsn. 8+ has an enhanced editor window.
- Program editor
: read/write, edit, save and submit code from this window.
- Log
: notes about the current SAS session including the submitted SAS statements, errors, warnings and dataset information.
- Output
: printable results, if any, from the procedures.
- Graphics
: any high resolution graphics submitted.
- Results
: this is like an index to the output window.
- Explorer
: like the MS-Windows explorer—it shows the accessible data libraries.
- Enhanced editor
: like the program window, but with some special effects.
Submitting a program (interactive mode): (Section 1.7)
- Input program into the program editor (type, open a text file).
- Edit code (if necessary).
- Submit the code (icon, menu, F3).
- Mark selected code and submit—this submits only the marked portion.
- Check the log and output windows to see if there are any errors, etc.
- Recall the text (icon, menu, F4)
- Return to step 2.
Also see The Little SAS® Book sections 1.8 (Reading the SAS log), 1.9 (Reading SAS output) and 1.10 (SAS options).