Jump to content

SAS/Basics

From Wikibooks, open books for an open world
< SAS


Why use SAS ?

[edit | edit source]
  • SAS works directly on the data sets without loading them into memory. This allows you to manipulate large database such as census data sets.

Why not use SAS ?

[edit | edit source]
  • SAS is not available for mac users
  • SAS is proprietary and expensive. You may prefer R which is open-source and cross-platforms.
  • There is no systematic syntax. The syntax is specific to each PROC.

Alternative to SAS

[edit | edit source]
  • R : an open source statistical package
  • Stata : includes the very latest econometric methods
  • SPSS : an easy to use statistical software

SAS Environment

[edit | edit source]
EDITOR (F5)
This is a text editor with syntax highlighting where you write your program. You can save your program with the .sas extension.
LOG (F6)
includes all information about the computing process such as errors, warnings, computing time (cpu). You can save it with the .log extension.
OUTPUT (F7)
This includes all the results. You can save it with the .lst extension.
EXPLORER (CTRL D)
browse all your SAS libraries and open datasets in the SAS data editor.
HELP (F1)
Help system.

SAS Programming Style

[edit | edit source]
  • SAS includes procedures and data step. data steps generally create a new dataset and procedure step compute some quantity of interest using existing data.
  • Each step is ended with the run ; statement.
  • Semicolons ; are end of statement delimiter.
  • SAS works directly on a database without loading it into memory. This facilitates manipulation of large databases.
  • F3 executes the current program or the selected lines of the program.
  • After executing a program, you first look at your log and then you can have a look at your results.
  • Comments begin with a star and terminated by a semicolon or are contained within a slash-star and a star-slash c-style block comment:
* This is a comment ; 
/*This is also a comment */
  • SAS is not case sensitive ("a" and "A" are similar to SAS)

Preamble

[edit | edit source]

The following lines are often useful at the beginning of a SAS program :

  • Libname : It is often useful to defines libname. A libname is nothing more than an alias for a directory.
libname lib_name 'c:/data/ee';
  • Options : the following line in head of a program makes it easier to read the log.
options errors=1 noovp pageno=1 ls=78;
  • Clean log and output windows : At the beginning of a program it is often convenient to clean the log and the output:
dm "CLEAR LOG ; CLEAR OUTPUT ; " ;

dm stands for "Display Manager"