DATA Step, Macro, Functions and more

Macro Processor: correct reasoning?

Reply
New Contributor
Posts: 2

Macro Processor: correct reasoning?

I am using SAS 9.4. I have the following code:

48221  %let userAsof='28FEB2018'd;
48222
48223  /*2.a)*/ %let lAsOf = intnx(month,&userAsOf.,0,e);
48224  %put lAsOf = &lAsof;
lAsOf = intnx(month,'28FEB2018'd,0,e)
48225
48226  /*2.b)*/ %let lAsOf = %sysfunc(intnx(month,&userAsOf.,0,e));
48227  %put lAsOf = &lAsof;
lAsOf = 21243

 

I am trying to reason as to why the two outputs are different by thinking about the steps that are taken chronologically behind the scenes. Please tell me if I am wrong or there is anything to be added on. Differences in the steps are highlighted in bold.

 

1. SAS recognizes the % sign to prompt the macro processor. userAsof is stored in Global Symbol table as text '28FEB2018'd.

 

2.A)

  • SAS recognizes the % sign to prompt the macro processor. lAsOf is stored in the Global Symbol table.
  • However, while evaluating the RHS expression, SAS recognizes the & sign to prompt the macro processor again. It finds the userAsof variable in the global symbol table and replaces the expression.
  • The rest of the RHS is not evaluated and remains as text because intnx is a datastep function and when setting a macro variable we're concerned with the macro processor and not the data step compiler.

 

2.B)

  • SAS recognizes the % sign to prompt the macro processor. lAsOf is stored in the Global Symbol table.
  • on the RHS, SAS recognizes the % sign to prompt the macro processor. sysfunc tells SAS to evaluate the intnx datastep function. So we go to the data step compiler to compile and execute the intnx datastep function.
    • while evaluating this expression, SAS recognizes the & sign to prompt the macro processor again. It finds the userAsof variable in the global symbol table and replaces the expression. Then SAS finishes compiling and executing the RHS expression.

Any help is appreciated. Thanks.

 

 

New Contributor
Posts: 2

Re: Macro Processor: correct reasoning?

Smiley Sad
Super User
Super User
Posts: 7,948

Re: Macro Processor: correct reasoning?

Doesn't sound like you need any help.

Ask a Question
Discussion stats
  • 2 replies
  • 45 views
  • 1 like
  • 2 in conversation