SlideShare a Scribd company logo
When Best to Use the %LET Statement, the SYMPUT Routine, or the INTO Clause to Create Macro Variables Arthur Li Department of Information Science City of Hope Comprehensive Cancer Center  Duarte, CA
INTRODUCTION DATA Step  PROC Steps SAS Macro  Facility BASE SAS Use to generate SAS codes more… PROC SQL
INTRODUCTION DATA Step  PROC Steps SAS Macro  Facility BASE SAS more… PROC SQL ,[object Object],[object Object],SAS Macro Variables SAS Macro  Programs Prerequisites: Focus of this talk
INTRODUCTION DATA Step  PROC Steps SAS Macro  Facility BASE SAS more… PROC SQL ,[object Object],[object Object],SAS Macro Variables SAS Macro  Programs Prerequisites: SAS Macro Variables SAS Macro Variables Automatic User- Defined Focus of this talk
THE %LET STATEMENT ,[object Object],%LET  MACRO-VARIABLE = VALUE; %let  var1 = 4 + 3; ,[object Object],MACRO-VARIABLE var1 VALUE 4 + 3 ,[object Object]
THE %LET STATEMENT ,[object Object],%LET  MACRO-VARIABLE = VALUE; %let  var2 =  leading blank; ,[object Object],MACRO-VARIABLE var2 VALUE leading blank ,[object Object]
THE %LET STATEMENT ,[object Object],%LET  MACRO-VARIABLE = VALUE; %let  var3 = " quotations "; ,[object Object],MACRO-VARIABLE var3 VALUE “  quotations ” ,[object Object]
THE %LET STATEMENT ,[object Object],%LET  MACRO-VARIABLE = VALUE; ,[object Object]
REFERENCING MACRO VARIABLES ,[object Object],%let  ht = 63;  ht  63 User-Defined Macro Variables: … … SYSTIME  10:34 SYSDAY  Monday SYSDATE  19JUN06 SAS Automatic Macro Variables: Global Symbol Table
REFERENCING MACRO VARIABLES ,[object Object],%let  ht = 63; data  ex1; set  height; tall = height > &ht; run ; ht  63 & MACRO-VARIABLE  63 ,[object Object],“ & MACRO-VARIABLE” User-Defined Macro Variables: … … SYSTIME  10:34 SYSDAY  Monday SYSDATE  19JUN06 SAS Automatic Macro Variables: Global Symbol Table
UNDERSTANDING SAS PROCESSING ,[object Object],Compilation phase Each statement is scanned for syntax errors Execution phase The DATA step reads and processes the input data the descriptor portion is created  If there is no syntax error Done in the compiler How are the SAS statements transferred to the compiler? A DATA step is processed in sequence in two phases
UNDERSTANDING SAS PROCESSING ,[object Object],data  ex1;  set  height; tall = height >  63 ; run ; INPUT STACK
[object Object],[object Object],[object Object],[object Object],UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK data  ex1;  set  height; tall = height >  63 ; run ;
data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ex1;  set  height; tall = height >  63 ; run ;
ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  set  height; tall = height >  63 ; run ;
; ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK set  height; tall = height >  63 ; run ;
set ; ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height; tall = height >  63 ; run ;
height set ; data  ex1 UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; tall = height >  63 ; run ;
; height set data  ex1; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK tall = height >  63 ; run ;
tall ; height data  ex1;  set UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK = height >  63 ; run ;
= tall ; data  ex1;  set height UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height >  63 ; run ;
height = tall data  ex1;  set height; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK >  63 ; run ;
> height = data  ex1;  set height; tall UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63 ; run ;
63 > height data  ex1;  set height; tall = UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ;
; 63 > data  ex1;  set height; tall = height UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK run ;
run ; 63 data  ex1;  set height; tall = height > UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;
; run ; data  ex1;  set height; tall = height >  63 UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
; run data  ex1;  set height; tall = height >  63 ; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
; data  ex1;  set height; tall = height >  63 ;  run UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
data  ex1;  set height; tall = height >  63 ;  run ; ,[object Object],UNDERSTANDING SAS PROCESSING Compilation phase Each statement is scanned for syntax errors.  Execution phase The DATA step reads and processes the input data. If there is no syntax error WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
UNDERSTANDING SAS PROCESSING Types of Token  Contains …  Examples  Literal  Characters enclosed in quotation marks “ John”  ‘John’  Numerals including decimals, E-notation, date, time, datetime constants, and hexadecimal constants 555 ‘ 01mar2010’d 30e4 Number Characters that begin with a letter or underscore and that continues with underscores, letters, or numbers.  A period can sometimes be part of a name _n_ means dollar9.2 Descending Name Characters other than a letter, number, or underscore that have a special meaning to the SAS system Special character /  +  %  &  . ;
[object Object],[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK %let  ht =63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR
[object Object],[object Object],[object Object],[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK %let  ht =63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR
% MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK let  ht =63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR
let % ,[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ht =63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR
ht let % MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR
= ht let % MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63;  data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables
; 63 = ht MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK data  ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables
data ; 63 = MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ex1;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht
ex1 data ; 63 ,[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  set  height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht
; ex1 data MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK set  height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
set ; ex1 data MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
height set ; data  ex1 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
; height set data  ex1; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK tall =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
tall ; height data  ex1;  set MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
= tall ; data  ex1;  set height MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
height = tall data  ex1;  set Height; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK >&ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
> height = data  ex1;  set height; tall MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK &ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
& > height data  ex1;  set height; tall = MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ht;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
ht & > data  ex1;  set height; tall = height ,[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
ht & data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
ht data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
ht data  ex1;  set height; tall = Height > ,[object Object],MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
ht data  ex1;  set height; tall = Height > 63   MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
data  ex1;  set height; tall = Height > 63   MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63 ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
63 data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
; 63 data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
run ; 63 data  ex1;  set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
; run ; data  ex1;  set height; tall = Height >  63 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
; run data  ex1;  set height; tall = Height >  63 ; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
; data  ex1;  set height; tall = Height >  63 ;  run MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
data  ex1;  set height; tall = Height >  63 ;  run; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . . User-Defined Macro Variables   ht  63
PROCESSING MACRO VARIABLES AT EXECUTION TIME ,[object Object],[object Object],[object Object],[object Object],[object Object]
PROCESSING MACRO VARIABLES AT EXECUTION TIME ,[object Object],[object Object],[object Object],[object Object],[object Object],Ex1: 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: data   _null_ ; set  ex1 end=last; if  tall  then  count_tall + 1 ; if  last  then   do ; if  count_tall  then   do ; %let  titl = "Some students are taller than 63 inches"; end ; else   do ; %let  titl = "None of the students are taller than 63 inches"; end ; end ; run ; 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: proc   print   data =ex1; title  &titl; run ; None of the students are taller than 63 inches Obs  name  sex  height  tall 1  John  m  65  1 2  Tom  m  60  0 3  Mary  f  62  0 4  Helen  f  64  1 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ;  %let  titl ="Some students are taller than 63 inches";  end ;  else   do ;  %let  titl =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables
titl let % data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ="Some students are taller than 63 inches";  end ;  else   do ;  %let  titl =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables
; do else data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK %let  titl =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  Some students are  taller than 63 inches
% ; do data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ;  else PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK let  titl =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  Some students are  taller than 63 inches
titl let % data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ;  else do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  Some students are  taller than 63 inches
let % ; data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ;  else do PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK titl =  "None of the students are taller than 63 inches";  end ;  end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  Some students are  taller than 63 inches
; end data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ;  else do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK end ;  run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  None of the students are taller than 63 inches
data   _null_ ;  set  ex1 end=last;  if  tall  then  count_tall + 1 ;  if  last  then   do ;  if  count_tall  then do ; end ;  else do ;  end ;  end ;  run ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE  19JUN06 SYSDAT  Monday SYSTIME  10:34 . . User-Defined Macro Variables   Titl  None of the students are taller than 63 inches
PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: data   _null_ ; set  ex1 end=last; if  tall  then  count_tall + 1 ; if  last  then   do ; if  count_tall  then   do ; %let  titl = "Some students are taller than 63 inches"; end ; else   do ; %let  titl = "None of the students are taller than 63 inches"; end ; end ; run ; Here is what the program will look like when it is processed by the compiler  64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
THE SYMPUT ROUTINE  ,[object Object],CALL SYMPUT  (MACRO-VARIABLE, VALUE); ,[object Object],[object Object],[object Object],[object Object]
THE SYMPUT ROUTINE  CALL SYMPUT  (MACRO-VARIABLE, VALUE); ,[object Object],‘ MACRO-VARIABLE’: Text enclosed in the quotation marks is the exact macro variable name ‘ VALUE’: The exact value that is assigned to the MACRO-VARIABLE
THE SYMPUT ROUTINE  data   _null_ ; set  ex1 end=last; if  tall  then  count_tall + 1 ; if  last  then   do ; if  count_tall  then   do ; call  symput( 'titl' ,  'Some students are taller than 63 inches' ); end ; else   do ; call  symput( 'titl' ,  'None of the students are taller than 63 inches' ); end ; end ; run ; ,[object Object]
THE SYMPUT ROUTINE  proc   print   data =ex1; title  &titl; run ; Some students are taller than 63 inches Obs  name  sex  height  tall 1  John  m  65  1 2  Tom  m  60  0 3  Mary  f  62  0 4  Helen  f  64  1
THE SYMPUT ROUTINE  CALL SYMPUT  (MACRO-VARIABLE, VALUE); ,[object Object],A DATA step variable; not in quotation marks ,[object Object],[object Object],[object Object]
THE SYMPUT ROUTINE  ,[object Object],Height: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name 64 Helen_ht 62 Mary_ht 60 Tom_ht 65 John_ht Values Macro Variable Names
THE SYMPUT ROUTINE  data   _null_ ; set  height; if  name =  'John'   then   call  symput ( 'John_ht' ,  height); else   if  name =  'Tom'   then   call  symput ( 'Tom_ht' ,  height); else   if  name =  'Mary'   then   call  symput ( 'Mary_ht' ,  height); else   if  name =  'Helen'   then   call  symput ( 'Helen_ht' , height); run ; Height: HEIGHT is not in quotation marks 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUT ROUTINE  %put  macro variable John_ht: &John_ht; %put  macro variable Tom_ht: &Tom_ht; %put  macro variable Mary_ht: &Mary_ht; %put  macro variable Helen_ht: &Helen_ht; Height: 359  %put macro variable John_ht: &John_ht; macro variable John_ht:  65 360  %put macro variable Tom_ht: &Tom_ht; macro variable Tom_ht:  60 361  %put macro variable Mary_ht: &Mary_ht; macro variable Mary_ht:  62 362  %put macro variable Helen_ht: &Helen_ht; macro variable Helen_ht:  64 Log: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUT ROUTINE  CALL SYMPUT  (MACRO-VARIABLE, VALUE); ,[object Object],A DATA step variable; not in quotation marks ,[object Object],[object Object]
THE SYMPUT ROUTINE  ,[object Object],Height: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name 64 Helen 62 Mary 60 Tom 65 John Values Macro Variable Names
THE SYMPUT ROUTINE  Height: data   _null_ ; set  height; call  symput (name, height); run ; NAME is not in quotation marks 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUT ROUTINE  Height: %put  macro variable John: &John; %put  macro variable Tom: &Tom; %put  macro variable Mary: &Mary; %put  macro variable Helen: &Helen; 368  %put macro variable John: &John; macro variable John:  65 369  %put macro variable Tom: &Tom; macro variable Tom:  60 370  %put macro variable Mary: &Mary; macro variable Mary:  62 371  %put macro variable Helen: &Helen; macro variable Helen:  64 Log: Notice that “blanks” are part of the macro variables 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUT ROUTINE  CALL SYMPUT  (MACRO-VARIABLE, VALUE); ,[object Object],A DATA step expression A DATA step expression
THE SYMPUT ROUTINE  ,[object Object],Height: ,[object Object],64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name 64 height_Helen 62 height_Mary 60 height_Tom 65 height_John Values Macro Variable Names
THE SYMPUT ROUTINE  Height: data   _null_ ; set  height; call  symput ( "height_"  ||name, trim(left(height))); run ; 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUT ROUTINE  Height: %put  macro variable height_John: &height_John; %put  macro variable height_Tom: &height_Tom; %put  macro variable height_Mary: &height_Mary; %put  macro variable height_Helen: &height_Helen; 411  %put macro variable height_John: &height_John; macro variable height_John: 65 412  %put macro variable height_Tom: &height_Tom; macro variable height_Tom: 60 413  %put macro variable height_Mary: &height_Mary; macro variable height_Mary: 62 414  %put macro variable height_Helen: &height_Helen; macro variable height_Helen: 64 Log: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
THE SYMPUTX ROUTINE  ,[object Object],[object Object],[object Object],data   _null_ ; set  height; call  symputx ( "height_"  ||name, height); run ;
THE SYMPUTX ROUTINE  %put  macro variable height_John: &height_John; %put  macro variable height_Tom: &height_Tom; %put  macro variable height_Mary: &height_Mary; %put  macro variable height_Helen: &height_Helen; 429  %put macro variable height_John: &height_John; macro variable height_John: 65 430  %put macro variable height_Tom: &height_Tom; macro variable height_Tom: 60 431  %put macro variable height_Mary: &height_Mary; macro variable height_Mary: 62 432  %put macro variable height_Helen: &height_Helen; macro variable height_Helen: 64 Log:
THE SYMPUTX ROUTINE  ,[object Object],CALL SYMPUTX  CALL SYMPUT  Does  not  write a note to the SAS log when the 2 nd  argument is numeric Writes a note to the SAS log when the 2 nd  argument is numeric Uses a field width of up to 32 characters for converting a numeric 2 nd  argument to characters Uses a field width of up to 12 characters for converting a numeric 2 nd  argument to characters Left-justifies both arguments and trims trailing blanks  Does not left-justify the arguments and trims trailing blanks from the first argument only Enables you to specify the symbol table  Does not enable you to specify the symbol table
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1 <, :macro-variable2, …> FROM  table |view <other clauses>; QUIT ; To select one or more columns from SQL table/view, you can specify column1, column2, … after the keyword SELECT
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1 <, :macro-variable2, …> FROM  table |view <other clauses>; QUIT ; Macro-variable1, macro-variable2 are the names of the macro variables that you are creating
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1 <, :macro-variable2, …> FROM  table |view <other clauses>; QUIT ; You must write colon(s) (:) before each of the macro variables
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1 <, :macro-variable2, …> FROM  table |view <other clauses>; QUIT ; The INTO clause does not trim the leading and trailing blanks of the macro variables
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1 <, :macro-variable2, …> FROM  table |view <other clauses>; QUIT ; To suppress display-output from PROC SQL, you can use the NOPRINT option
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],[object Object],proc   sql   noprint ; select  mean(height)  into : mean_ht from  height; quit ; %put  macro variable mean_ht: &mean_ht; 523  %put macro variable mean_ht: &mean_ht; macro variable mean_ht:  62.75 Log:
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],proc   means   data =height  noprint ; var  height; output   out =height_mean  mean =ht_mean; run ; data   _null_ ; set  height_mean; call  symputx( 'mean_ht1' , ht_mean); run ;
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],data   _null_ ; set  height; if  name =  'John'   then   call  symput ( 'John_ht' ,  height); else   if  name =  'Tom'   then   call  symput ( 'Tom_ht' ,  height); else   if  name =  'Mary'   then   call  symput ( 'Mary_ht' ,  height); else   if  name =  'Helen'   then   call  symput ( 'Helen_ht' , height); run ; ,[object Object],proc   sql   noprint ; select  height  into : John_ht1  from  height where  name =  'John' ; select  height  into : Tom_ht1  from  height where  name =  'Tom' ; select  height  into : Mary_ht1  from  height where  name =  'Mary' ; select  height  into : Helen_ht1  from  height where  name =  'Helen' ; quit ;
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1_1 -  :macro-variable1_n < NOTRIM> <, :macro-variable2_1 -  :macro-variable2_n < NOTRIM>, …> FROM  table |view <other clauses>; QUIT ;
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1_1 -  :macro-variable1_n < NOTRIM> <, :macro-variable2_1 -  :macro-variable2_n < NOTRIM>, …> FROM  table |view <other clauses>; QUIT ; into :name1 - :name4,  :height1 - :height4 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name name1 name2 name3 name4 height1 height2 height3 height4
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …> INTO  :macro-variable1_1 -  :macro-variable1_n < NOTRIM> <, :macro-variable2_1 -  :macro-variable2_n < NOTRIM>, …> FROM  table |view <other clauses>; QUIT ; ,[object Object],[object Object]
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],proc   sql   noprint ; select  name, height  into  :name1 - :name4,    :height1 - :height4 from  height; quit ; %put  macro variable name1: &name1; %put  macro variable name2: &name2; %put  macro variable name3: &name3; %put  macro variable name4: &name4; %put  macro variable height1: &height1; %put  macro variable height2: &height2; %put  macro variable height3: &height3; %put  macro variable height4: &height4;
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],663  %put macro variable name1: &name1; macro variable name1: John 664  %put macro variable name2: &name2; macro variable name2: Tom 665  %put macro variable name3: &name3; macro variable name3: Mary 666  %put macro variable name4: &name4; macro variable name4: Helen 667  %put macro variable height1: &height1; macro variable height1: 65 668  %put macro variable height2: &height2; macro variable height2: 60 669  %put macro variable height3: &height3; macro variable height3: 62 670  %put macro variable height4: &height4; macro variable height4: 64
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],[object Object],[object Object],[object Object]
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],PROC SQL  <PRINT|NOPRINT>; SELECT  column1 <, column2, …>  INTO  :macro-variable1  SEPARATED  BY ‘delimiter1’ <, :macro-variable2  SEPARATED  BY ‘delimiter2’, …> FROM  table |view <other clauses>; QUIT ; Delimiter1 is used to separate all the values in the column and must be enclosed in quotation marks
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],Macro Variable Value  NAMELIST John Tom Mary Helen HEIGHTLIST 65,60,62,64  64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],871  %put macro variable namelist: &namelist; macro variable namelist: John Tom Mary Helen 872  %put macro variable heightlist: &heightlist; macro variable heightlist: 65,60,62,64
CONCLUSION ,[object Object],[object Object],[object Object],[object Object]
REFERENCES ,[object Object],[object Object]
ACKNOWLEDGEMENT  ,[object Object]
CONTACT INFORMATION ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

Viewers also liked

SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
venkatam
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
venkatam
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
guest2160992
 
SAS Macro practice
SAS Macro practiceSAS Macro practice
SAS Macro practice
Ping Yin
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
venkatam
 
Habits of Effective SAS Programmers
Habits of Effective SAS ProgrammersHabits of Effective SAS Programmers
Habits of Effective SAS Programmers
Sunil Gupta
 
Market Basket Analysis in SAS
Market Basket Analysis in SASMarket Basket Analysis in SAS
Market Basket Analysis in SAS
Andrew Kramer
 
Motivating Clinical Sas Programmers
Motivating Clinical Sas ProgrammersMotivating Clinical Sas Programmers
Motivating Clinical Sas Programmers
Daniel Boisvert
 
Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programming
ray4hz
 

Viewers also liked (9)

SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
 
SAS Macro practice
SAS Macro practiceSAS Macro practice
SAS Macro practice
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
Habits of Effective SAS Programmers
Habits of Effective SAS ProgrammersHabits of Effective SAS Programmers
Habits of Effective SAS Programmers
 
Market Basket Analysis in SAS
Market Basket Analysis in SASMarket Basket Analysis in SAS
Market Basket Analysis in SAS
 
Motivating Clinical Sas Programmers
Motivating Clinical Sas ProgrammersMotivating Clinical Sas Programmers
Motivating Clinical Sas Programmers
 
Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programming
 

Similar to When best to use the %let statement, the symput routine, or the into clause to create macro variables

SAS macro processing vs with out macro processing
SAS macro processing vs with out macro processingSAS macro processing vs with out macro processing
SAS macro processing vs with out macro processing
SAYAN DAS
 
Sas macros part 4.1
Sas macros part 4.1Sas macros part 4.1
Sas macros part 4.1
venkatam
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
venkatam
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
Timothy Spann
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
Frank Kim
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
Sonal Shrivastav
 
Combres
CombresCombres
Combres
Buu Nguyen
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
rowensCap
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
phanleson
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
Carol McDonald
 
Goto devoxx
Goto devoxxGoto devoxx
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
Paul Brebner
 
Dataservices: Processing (Big) Data the Microservice Way
Dataservices: Processing (Big) Data the Microservice WayDataservices: Processing (Big) Data the Microservice Way
Dataservices: Processing (Big) Data the Microservice Way
QAware GmbH
 
Ss4
Ss4Ss4
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
Paul Brebner
 
Kamaelia Protocol Walkthrough
Kamaelia Protocol WalkthroughKamaelia Protocol Walkthrough
Kamaelia Protocol Walkthrough
kamaelian
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
guest5de1a5
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
Carol McDonald
 
2. introduction
2. introduction2. introduction
2. introduction
Saeed Parsa
 
Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0
Anyscale
 

Similar to When best to use the %let statement, the symput routine, or the into clause to create macro variables (20)

SAS macro processing vs with out macro processing
SAS macro processing vs with out macro processingSAS macro processing vs with out macro processing
SAS macro processing vs with out macro processing
 
Sas macros part 4.1
Sas macros part 4.1Sas macros part 4.1
Sas macros part 4.1
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
 
Combres
CombresCombres
Combres
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Goto devoxx
Goto devoxxGoto devoxx
Goto devoxx
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
 
Dataservices: Processing (Big) Data the Microservice Way
Dataservices: Processing (Big) Data the Microservice WayDataservices: Processing (Big) Data the Microservice Way
Dataservices: Processing (Big) Data the Microservice Way
 
Ss4
Ss4Ss4
Ss4
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
 
Kamaelia Protocol Walkthrough
Kamaelia Protocol WalkthroughKamaelia Protocol Walkthrough
Kamaelia Protocol Walkthrough
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
2. introduction
2. introduction2. introduction
2. introduction
 
Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0Continuous Application with Structured Streaming 2.0
Continuous Application with Structured Streaming 2.0
 

Recently uploaded

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 

Recently uploaded (20)

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 

When best to use the %let statement, the symput routine, or the into clause to create macro variables

  • 1. When Best to Use the %LET Statement, the SYMPUT Routine, or the INTO Clause to Create Macro Variables Arthur Li Department of Information Science City of Hope Comprehensive Cancer Center Duarte, CA
  • 2. INTRODUCTION DATA Step PROC Steps SAS Macro Facility BASE SAS Use to generate SAS codes more… PROC SQL
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ex1; set height; tall = height > 63 ; run ;
  • 15. ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; set height; tall = height > 63 ; run ;
  • 16. ; ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK set height; tall = height > 63 ; run ;
  • 17. set ; ex1 data UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height; tall = height > 63 ; run ;
  • 18. height set ; data ex1 UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; tall = height > 63 ; run ;
  • 19. ; height set data ex1; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK tall = height > 63 ; run ;
  • 20. tall ; height data ex1; set UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK = height > 63 ; run ;
  • 21. = tall ; data ex1; set height UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height > 63 ; run ;
  • 22. height = tall data ex1; set height; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK > 63 ; run ;
  • 23. > height = data ex1; set height; tall UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63 ; run ;
  • 24. 63 > height data ex1; set height; tall = UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ;
  • 25. ; 63 > data ex1; set height; tall = height UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK run ;
  • 26. run ; 63 data ex1; set height; tall = height > UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ;
  • 27. ; run ; data ex1; set height; tall = height > 63 UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
  • 28. ; run data ex1; set height; tall = height > 63 ; UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
  • 29. ; data ex1; set height; tall = height > 63 ; run UNDERSTANDING SAS PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK
  • 30.
  • 31. UNDERSTANDING SAS PROCESSING Types of Token Contains … Examples Literal Characters enclosed in quotation marks “ John” ‘John’ Numerals including decimals, E-notation, date, time, datetime constants, and hexadecimal constants 555 ‘ 01mar2010’d 30e4 Number Characters that begin with a letter or underscore and that continues with underscores, letters, or numbers. A period can sometimes be part of a name _n_ means dollar9.2 Descending Name Characters other than a letter, number, or underscore that have a special meaning to the SAS system Special character / + % & . ;
  • 32.
  • 33.
  • 34. % MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK let ht =63; data ex1; set height; tall =height >&ht; run ; MACRO PROCESSOR
  • 35.
  • 36. ht let % MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =63; data ex1; set height; tall =height >&ht; run ; MACRO PROCESSOR
  • 37. = ht let % MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63; data ex1; set height; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables
  • 38. ; 63 = ht MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK data ex1; set height; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables
  • 39. data ; 63 = MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ex1; set height; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht
  • 40.
  • 41. ; ex1 data MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK set height; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 42. set ; ex1 data MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 43. height set ; data ex1 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 44. ; height set data ex1; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK tall =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 45. tall ; height data ex1; set MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 46. = tall ; data ex1; set height MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK height >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 47. height = tall data ex1; set Height; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK >&ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 48. > height = data ex1; set height; tall MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK &ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 49. & > height data ex1; set height; tall = MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ht; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 50.
  • 51. ht & data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 52. ht data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 53.
  • 54. ht data ex1; set height; tall = Height > 63 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 55. data ex1; set height; tall = Height > 63 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 56. data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK 63 ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 57. 63 data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 58. ; 63 data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 59. run ; 63 data ex1; set height; tall = Height > MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 60. ; run ; data ex1; set height; tall = Height > 63 MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 61. ; run data ex1; set height; tall = Height > 63 ; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 62. ; data ex1; set height; tall = Height > 63 ; run MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 63. data ex1; set height; tall = Height > 63 ; run; MACRO PROCESSING WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . . User-Defined Macro Variables ht 63
  • 64.
  • 65.
  • 66. PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; %let titl = &quot;Some students are taller than 63 inches&quot;; end ; else do ; %let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
  • 67. PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: proc print data =ex1; title &titl; run ; None of the students are taller than 63 inches Obs name sex height tall 1 John m 65 1 2 Tom m 60 0 3 Mary f 62 0 4 Helen f 64 1 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
  • 68. PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; %let titl =&quot;Some students are taller than 63 inches&quot;; end ; else do ; %let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables
  • 69. titl let % data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK =&quot;Some students are taller than 63 inches&quot;; end ; else do ; %let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables
  • 70. ; do else data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK %let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl Some students are taller than 63 inches
  • 71. % ; do data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; else PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl Some students are taller than 63 inches
  • 72. titl let % data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; else do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl Some students are taller than 63 inches
  • 73. let % ; data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; else do PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl Some students are taller than 63 inches
  • 74. ; end data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; else do ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK end ; run ; MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl None of the students are taller than 63 inches
  • 75. data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; end ; else do ; end ; end ; run ; PROCESSING MACRO VARIABLES AT EXECUTION TIME WORD SCANNER TOKENNIZER DETERMINE DESTINATION COMPILER INPUT STACK MACRO PROCESSOR GLOBAL SYMBOL TABLE SAS Automatic Macro Variables SYSDATE 19JUN06 SYSDAT Monday SYSTIME 10:34 . . User-Defined Macro Variables Titl None of the students are taller than 63 inches
  • 76. PROCESSING MACRO VARIABLES AT EXECUTION TIME Ex1: data _null_ ; set ex1 end=last; if tall then count_tall + 1 ; if last then do ; if count_tall then do ; %let titl = &quot;Some students are taller than 63 inches&quot;; end ; else do ; %let titl = &quot;None of the students are taller than 63 inches&quot;; end ; end ; run ; Here is what the program will look like when it is processed by the compiler 64 62 60 65 height 1 f Helen 4 0 f Mary 3 0 m Tom 2 1 m John 1 tall sex name
  • 77.
  • 78.
  • 79.
  • 80. THE SYMPUT ROUTINE proc print data =ex1; title &titl; run ; Some students are taller than 63 inches Obs name sex height tall 1 John m 65 1 2 Tom m 60 0 3 Mary f 62 0 4 Helen f 64 1
  • 81.
  • 82.
  • 83. THE SYMPUT ROUTINE data _null_ ; set height; if name = 'John' then call symput ( 'John_ht' , height); else if name = 'Tom' then call symput ( 'Tom_ht' , height); else if name = 'Mary' then call symput ( 'Mary_ht' , height); else if name = 'Helen' then call symput ( 'Helen_ht' , height); run ; Height: HEIGHT is not in quotation marks 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 84. THE SYMPUT ROUTINE %put macro variable John_ht: &John_ht; %put macro variable Tom_ht: &Tom_ht; %put macro variable Mary_ht: &Mary_ht; %put macro variable Helen_ht: &Helen_ht; Height: 359 %put macro variable John_ht: &John_ht; macro variable John_ht: 65 360 %put macro variable Tom_ht: &Tom_ht; macro variable Tom_ht: 60 361 %put macro variable Mary_ht: &Mary_ht; macro variable Mary_ht: 62 362 %put macro variable Helen_ht: &Helen_ht; macro variable Helen_ht: 64 Log: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 85.
  • 86.
  • 87. THE SYMPUT ROUTINE Height: data _null_ ; set height; call symput (name, height); run ; NAME is not in quotation marks 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 88. THE SYMPUT ROUTINE Height: %put macro variable John: &John; %put macro variable Tom: &Tom; %put macro variable Mary: &Mary; %put macro variable Helen: &Helen; 368 %put macro variable John: &John; macro variable John: 65 369 %put macro variable Tom: &Tom; macro variable Tom: 60 370 %put macro variable Mary: &Mary; macro variable Mary: 62 371 %put macro variable Helen: &Helen; macro variable Helen: 64 Log: Notice that “blanks” are part of the macro variables 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 89.
  • 90.
  • 91. THE SYMPUT ROUTINE Height: data _null_ ; set height; call symput ( &quot;height_&quot; ||name, trim(left(height))); run ; 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 92. THE SYMPUT ROUTINE Height: %put macro variable height_John: &height_John; %put macro variable height_Tom: &height_Tom; %put macro variable height_Mary: &height_Mary; %put macro variable height_Helen: &height_Helen; 411 %put macro variable height_John: &height_John; macro variable height_John: 65 412 %put macro variable height_Tom: &height_Tom; macro variable height_Tom: 60 413 %put macro variable height_Mary: &height_Mary; macro variable height_Mary: 62 414 %put macro variable height_Helen: &height_Helen; macro variable height_Helen: 64 Log: 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name
  • 93.
  • 94. THE SYMPUTX ROUTINE %put macro variable height_John: &height_John; %put macro variable height_Tom: &height_Tom; %put macro variable height_Mary: &height_Mary; %put macro variable height_Helen: &height_Helen; 429 %put macro variable height_John: &height_John; macro variable height_John: 65 430 %put macro variable height_Tom: &height_Tom; macro variable height_Tom: 60 431 %put macro variable height_Mary: &height_Mary; macro variable height_Mary: 62 432 %put macro variable height_Helen: &height_Helen; macro variable height_Helen: 64 Log:
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106. PROCESSING MACRO VARIABLES DURING THE EXECUTION OF PROC SQL PROC SQL <PRINT|NOPRINT>; SELECT column1 <, column2, …> INTO :macro-variable1_1 - :macro-variable1_n < NOTRIM> <, :macro-variable2_1 - :macro-variable2_n < NOTRIM>, …> FROM table |view <other clauses>; QUIT ; into :name1 - :name4, :height1 - :height4 64 62 60 65 height f Helen 4 f Mary 3 m Tom 2 m John 1 sex name name1 name2 name3 name4 height1 height2 height3 height4
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.