SAS Quick Reference

General Notes

The Little SAS Book by Lora D. Delwiche and Susan J. Slaughter

::General Advice::

SAS and SQL have a lot in common, if you have used postgre SQL you will be familiar with SAS.

:: Basic ::

*comment;
/*comment*/

SAS does not care about capitlisation in either direction.
Indentation is allowed, but has no effect on code.
SAS statements end with a semicolon

Observations (rows)
Variables (columns)

 

Inputting Data

Data Types (only 2):

Numeric – if it contains ONLY numbers, its numeric. Numerica can contain negative sign. Missing numberical data is represented by ‘.’.
Character – if it contains letters, its character. Missing character data is represented by blank.

SAS programs have two sections(Data and Proc):

Data: Data is basically the input, defining variables, etc. Generally any functions or methods acting on the data will occur in this section. This section will begin with the word ‘data’

Proc: Proc is short for processing and is somewhat more limited. It is basically a call to an inbuilt SAS function, PRINT to just display but there can be more advanced math and stats functions here like MEAN. This section will begin with the word ‘proc’

EXAMPLE:

DATA data_name; * Create a data set named ‘data_name’, data sets are very similar to tables;
PROC PRINT DATA = data_name; * Print the dataset named ‘data_name’;
RUN; * Run the program;

Note: You can chain these together, so it can go DATA->PROC->DATA->PROC

DATA data_set_name; * Create a data set named data_set_name;
column1 = 50; * add a column to the data set called ‘column1’ and enter its first value as 50;
column2 = 2 * column1; * add a column to the data set called ‘column2’ and calculate its value as 2 mulitplied by column1;
PROC PRINT DATA = data_set_name;
RUN;

:: Importing Data ::

Input Styles:

SAS has three input styles, from simplest and least powerful onward they are:

List Style: Automatically scans to the next non-blank field and starts reding.
Column Style: Starts reading in the specified column.
Formatted Style: Starts reading wherever the pointer is. @n is the command for explicit column moving.

Imported items can be find in the menu typically in Libraries -> My Libraries -> WORK.

Excel files:

Import and import wizard for bringing data into SAS.

SAS can also process raw data files, for instance: .txt files, ASCII, sequential or flat files.

DATALINES statement: used to indicate internal data.

INFILE ’c:\Directory\President.dat’; * This references an external data source;

DATA a_data_set; * Create a SAS data set named a_data_set;
INFILE ’c:\Directory\MyFile.dat’; * Access the file MyFile.dat file via its path.
INPUT Column1 $ Column2 Column3 Column4; * Create a series of columns?????;
PROC PRINT DATA = toads; * Print the data to verify it is correct;
TITLE ’SAS a_data_set’; * This gives the title of the data set;
RUN;

: Reading Messy Data

@’character’ # This will find the specific string ‘character’. It is used as below:

INPUT @’character_string:’ column_name $; # This will search for the string ‘character_string’ and then add the text after that to the ‘column_name’ column. It will only work if the text after the phrase ‘character_string is 8 characters or less.;

INPUT @’character_string:’ column_name $20.; # This will be the same as the above, but will read for 20 characters instead of 8;
INPUT @’character_string:’ column_name :$20; # This will read for 20 characters and stop at a space;

# You do not always need to tell SAS to search over different lines of a document, but it can be considered best practice as follows:

INPUT Column1_name $ Column2_name $
/ Column_High Column_Low # The ‘/’ symbol tells SAS to move to another line of the input file;
#3 Column_Max_High Column_Max_Low; # The #3 tells SAS to move to another line.;

 

 

@@@ PAGE 72 pdf The Little SAS Book @@@

 

Selecting Data

 

 

Processing Data

 

 

Displaying Data

 

 

 

Outputting Data

 

 

Glossary of Terms

 

 

Common Issues

SAS Stuck on Initializing (University Edition)

Try putting the address, typically http://localhost:10080, into another browser. I’ve experienced issues with this on Chrome but it worked fine on Edge.

print