Lesson 1, Part 3: SAS Program Flow¶

How SAS Processes Statements

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]:
No description has been provided for this image
  • The SAS code is submitted.
  • SAS statements are held in the Input Stack.
  • The Word Scanner parses the SAS statements into tokens
  • Tokens are sent to the Data Step Compiler for syntax checking and execution.
  • If the Word Scanner finds macro triggers (& or %), it sends them to Macro Processor.
  • In Macro Processor macro statements are executed and macro variable references are resolved.
  • The output from the macro processor is sent back to the Input Stack/Word Scanner.
  • If the Word Scanner does not detect any more macro language elements, the SAS code is sent to the Data Step Compiler.

Note: Macros/macro variables are resolved before the compilation phase (i.e., before the PDV is created)

List of SAS Tokens

  • 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;