You are on page 1of 2

SAS® Cheat Sheet

SAS Language Sum: variable+expression MISSING(argument) Indicates whether the argument


Adds the result of an expression to an accumulator var. contains a missing value
ATTRIB varn <LENGTH=’varn-length’> <LABEL=’varn-label’>
TITLE <n> <”text”>; MOD(argument1, argument2) Returns the remainder
<FORMAT=varn-format.> <INFORMAT=varn-informat.>;
Specifies title lines for SAS output. n specifies the relative MONTH(date) Returns the month from a SAS date value
Associates a format, informat, label, and/or length with one
line number with n being between 1 and 10. RANK(x) Returns the position of a character x in the ASCII
or more variables
WHERE where-expression; or EBCDIC collating sequence
CARDS or CARDS4 | DATALINES or DATALINES4
Selects observations from SAS data sets that meet a REPEAT(‘character-expression’,n) Repeats a character
Indicates that data lines follow (suffix of 4 if data has ‘;’s).
particular condition that is true. expression n+1 times.
DATA <dsetn <(dset-optionsn)>>;
RIGHT(argument) Right-aligns a character expression
Begins a DATA step and provides names for any output SAS Data Set Options ROUND(argument,round-off-unit) Rounds to the nearest
SAS data sets. See Data Set Options for options that are DROP=variable(s) Excludes variables from processing. round-off unit
available in the DATA statement. FIRSTOBS=n Specifies the first observation to process SCAN(argument,n<,delimiters>) Returns a given word from
DO index-var=start_value TO end_value <BY step>; IN=variable Creates and names a variable that indicates a character expression
DO UNTIL (expression); whether the data set contributed data to the current SUBSTR(argument,position<,n>) Extracts a substring from
DO WHILE (expression); observation. an argument.
Groups a set of statements as a single unit. Note that KEEP=variable(s) Selects variables for processing. TIME() Returns the current time of day
UNTIL conditions are evaluated at the end of the loop and LABEL='label' Specifies a label for a SAS data set TIMEPART(datetime) Extracts a time value from a SAS
thus execute at least once. OBS=n Specifies the first n observations to process datetime value
FILE filename <options>; POINT=variable Direct observation number variable TODAY() Returns the current date as a SAS date value
Specifies the current output file for PUT statements. RENAME=(oldname1=newname1 <...oldnamen=newnamen>) TRANSLATE(source,to,from) Replaces specific characters in
Options include: Changes the name of a variable. a character expression
MOD output is appended to an existing file. WHERE=(expression1 <logical-operator expressionn>) SUM(argument,argument, ...) Returns the total value of the
OLD output overwrites an existing file. Selects observations from a SAS data set that meet numeric arguments
IF expression THEN statement; .... <ELSE> statement; certain conditions before SAS brings them into the DATA TRIM(argument) Takes the argument and removes any
SAS evaluates the expression in an IF statement to or PROC step for processing. trailing blanks.
produce a result that is either non-zero, zero, or missing. If
result >0 then TRUE, else FALSE. SAS Functions UPCASE(argument) Converts all letters in an argument to
BYTE(n) Returns one character in the ASCII or EBCDIC uppercase
INFILE filename <options>;
collating sequence where n is an integer representing a WEEKDAY(date) Returns the day of the week from a SAS
Specifies an external file to read with an INPUT statement.
specific ASCII or EBCDIC character date value
Options include:
COMPBL(source) Removes multiple blanks from a character YEAR(date) Returns the year from a SAS date value
DELIMITER|DLM= delimiters
Specifies a delimiter for list input. string SAS Formats
LENGTH= variable COMPRESS(source<,characters-to-remove>) w.d standard numeric
Names a variable that SAS sets to the length of the Removes specific characters from a character string COMMAw.d writes numeric values with commas and
current input line. DATE() Returns the current date as a SAS date value decimal points
INPUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>; DATEPART(datetime) Extracts the date from a SAS Zw.d print leading zeros
INPUT <pointer-control> variable informat. <@ | @@>; datetime value $w. writes standard character data
INPUT <pointer-control> variable <$> <&> <@ | @@>; DATETIME() Returns the current date and time of day $CHARw. writes standard character data (including
Input records from the current input file, placing the values DAY(date) Returns the day of the month from a SAS date leading blanks)
into SAS variables. value $VARYINGw. Writes character data of varying length
MERGE ds1 <(doptions)> <... dsn<(doptions)>> <END=var>; HMS(hour,minute,second) Returns a SAS time value from
Joins observations from two or more SAS data sets into hour, minute, and second SAS Informats
single observations. INDEX(source,excerpt) Searches the source for the w.d Reads standard numeric data
OUTPUT<data-set-name(s)>; character string specified by the excerpt datew. Reads date values (ddmmmyy)
Writes the current observation to a SAS data set. LEFT(argument) Left-aligns a SAS character string $w. Reads standard character data
PUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>; LENGTH(argument) Returns the length of an argument $VARYINGw. Reads character data of varying length
PUT <pointer-control> <”text”|variable format.> <@ | @@>; LOWCASE(argument) Converts all letters in an argument to Compliments of:
Writes variable values and/or text to the output line. lowercase David Franklin
RETAIN variablen <initial-valuen>; MAX(argument,argument, ...) Returns the largest value of New Hampshire, USA
Causes a variable to retain its value from one iteration of the numeric arguments Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809
the data step to the next. MDY(month,day,year) Returns a SAS date value from Email 100316.3451@compuserve.com
SET <data-set(s) <(data-set-options(s)>> <POINT=varname> month, day, and year Google “Franklin SAS”
<NOBS=varname> <END=varname>; MIN(argument,argument, ...) Returns the smallest value of http://ourworld.compuserve.com/homepages/dfranklinuk
Reads observations from one or more data sets. the numeric arguments Release 1.2b ©MMVII
SAS® Cheat Sheet
SAS Procedures PROC FREQ <DATA=dset> PROC SORT <DATA=dset> <OUT=dset>
<ORDER=DATA|EXTERNAL|FREQ|INTERNAL>; <NODUPKEY|NODUPS>;
PROC COMPARE <BASE=dset> <COMPARE=dset>;
BY <DESCENDING> varn; BY <DESCENDING> variable-list;
BY variable(s);
TABLES requests </tables-options>; PROC TRANSPOSE <DATA=dset> <OUT=dset>;
ID variable(s);
where BY <DESCENDING> variable-list;
VAR variable(s);
requests one or more variable names joined by ID variable;
PROC DATASETS <LIBRARY=libref> <MEMTYPE=(m-list)> asterisks that specify the form of the VAR variable1 … variablen;
<DETAILS|NODETAILS> <KILL> generated tables, e.g. A*B
<NOLIST>; tables-options Can be one or more of the following: Macro Language
APPEND BASE=dset <DATA=dset> <FORCE>; LIST MISSING %DO macro-var=start_value %TO end_value <%BY step>;
CHANGE old-namen=new-namen </MEMTYPE=(m-list); NOPRINT OUT=SAS-data-set Executes a section of a macro repetitively based on the
CONTENTS <DATA=<libref.>member> <DIRECTORY> OUTPCT SPARSE value of an index variable
<MEMTYPE=(m-list)> <NODS> %DO %WHILE (expression);
PROC MEANS <DATA=dset> <DESCENDING>
<VARNUM> <NOPRINT> <OUT=dset>; Executes a section of a macro repetitively while a condition
<MISSING> <NOPRINT> <NWAY>
COPY OUT=libref <IN=libref> <MEMTYPE=(m-list)> is true
<ORDER=DATA|EXTERNAL|FREQ|
<MOVE>; %DO %UNTIL (expression);
INTERNAL>
EXCLUDE member-list </MEMTYPE=mtype>; Executes a section of a macro repetitively until a condition
<statistic-list>;
SELECT member-list </MEMTYPE=mtype>; is true
VAR variable-list;
DELETE member-list </ MEMTYPE=mtype>; %GLOBAL macro-variable(s);
CLASS variable-list;
MODIFY member-name <(<LABEL=’data-set-label’|’ ‘> Creates macro variables that are available during the
OUTPUT <OUT=dset> <out-statistic>;
<SORTEDBY=sort-information>)>; execution of an entire SAS session
where
FORMAT variable-format-name.; %IF expression %THEN action; <%ELSE action;>
statistic-list Can be one or more of the following:
INDEX CREATE variable </<UNIQUE> <NOMISS>>; Conditionally process a portion of a macro
N, NMISS, MIN, MAX, RANGE,
INDEX CREATE index=(variable-list) </<UNIQUE> %LENGTH (character string | text expression)
MEDIAN, SUM, MEAN, VAR, STD,
<NOMISS>>; Returns the length of a string
Q1, Q3, T
INDEX DELETE index-list; %LET macro-variable =<value>;
out-statistic Specifies the statistics in the output and
LABEL variable=’label-text’; Creates a macro variable and assigns it a value
also names the variable(s) that contain
RENAME variablen=new-variablen; %MACRO m-name (<pp1><…,ppn><kp1=value<..<kpn=v>);
the results.
QUIT; Begins a macro definition
where PROC REPORT <DATA=dset> <HEADLINE> <HEADSKIP>
%MEND <macro-name>;
m-list one or more of the member types that <NOWINDOWS> <SPACING=number>;
Ends a macro definition
processing should be restricted to. COLUMNS <report-item1, <., report-itemn>>
%SCAN(argumentn<,delimiters>)
member-list list of members in the directory to (`header1 ' < . `headern '> report-item(s) );
Search for a word that is specified by its position in a string
process. DEFINE report-item / <usage> <define-options>;
%SUBSTR(argument,position<,length>)
mtype restricts processing to one member type. COMPUTE <BEFORE|AFTER> report-item;
Produce a substring of a character string
LINE <item item-format | 'text' | pointer-control>;
PROC EXPORT DATA=<libref.>dset %UPCASE(character string | text expression)
ENDCOMP;
OUTFILE="filename" <REPLACE>; Convert values to uppercase
BREAK BEFORE|AFTER break-variable </b-option(s)>;
PROC IMPORT DATAFILE="filename" Macro Quoting
QUIT;
OUT=<libref.>dset <REPLACE>; %QUOTE | %NRQUOTE and %BQUOTE | %NRBQUOTE
where
The following filetypes are the most commonly used and Mask special characters and mnemonic operators in a
report-item name or alias (established in the
supported within filename by SAS: resolved value at macro execution
COLUMN statement) of the data set or
filename.XLS (Microsoft Excel) %STR | %NRSTR
computed variable, or statistic to define
filename.TXT (tab delimited) Mask special characters and mnemonic operators in
usage Either ACROSS, ANALYSIS,
filename.CSV (comma separated value) constant text at macro compilation
COMPUTED, DISPLAY, GROUP,
PROC FORMAT <CNTLIN=dset> %SUPERQ
ORDER
<CNTLOUT=dset> Masks special characters/mnemonic operators at macro
define-options The following options are available:
<LIBRARY=libref<.catalog>>; execution but prevents further resolution of the value.
FORMAT=format ORDER=
INVALUE <$>name <value-range-set(s)>; SPACING= WIDTH= Compliments of:
PICTURE name <...value-range-set <(picture-option(s))>>; DESCENDING FLOW David Franklin
VALUE <$>name <value-range-set>; NOPRINT CENTER New Hampshire, USA
where LEFT RIGHT Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809
picture-options The following options are useful: COLOR= ‘column-header’ Email 100316.3451@compuserve.com
ROUND NOEDIT b-options These include: Google “Franklin SAS”
PREFIX= FILL= SKIP PAGE http://ourworld.compuserve.com/homepages/dfranklinuk
Release 1.2b ©MMVII

You might also like