Lesson 1, Part 3: SAS Program Flow¶
In [4]:
from IPython.display import Image
Image("C:/Data/Macro_Diagram_x.png")
#Source: https://www.analyticsvidhya.com/blog/2015/12/complete-tutorial-sas-macros-faster-data-manipulation/
Out[4]:
- The
SAScode is submitted. - SAS statements are held in the
Input Stack. - The
Word Scannerparses the SAS statements intotokens - Tokens are sent to the
Data Step Compilerfor syntax checking and execution. - If the
Word Scannerfindsmacro triggers(& or %), it sends them toMacro Processor. - In
Macro Processormacro statements are executed andmacro variable referencesare resolved. - The output from the
macro processoris sent back to theInput Stack/Word Scanner. - If the
Word Scannerdoes not detect any more macro language elements, the SAS code is sent to theData Step Compiler.
Note: Macros/macro variables are resolved before the compilation phase (i.e., before the PDV is created)
- Literal: One or more characters enclosed in single or double quotation marks.
'CARY'
"2008"
- Name: One or more characters beginning with a letter or an underscore. Other characters can be letters, underscores, and digits.
data _test linesleft f25
univariate otherwise year_2008 descending
- Number: A numeric value Integers or Real (floating point) numbers.
1, 72, and 5000
'24AUG2008'D
2.35, 5., 2.3E1, and 5.4E− 1
- Special character. Any character that is not a letter, number, or underscore
= + − % & ; ( ) #
MACRO PROCESSOR – The Masked Warrior
%macro sortit;
proc sort data=&syslast;
by study subject gender;
run;
%mend sortit;
%sortit;