View previous topic :: View next topic
|
Author |
Message |
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1743 Location: Tirupur, India
|
|
|
|
Hello,
I am trying to understand how SAS macro variables are getting resolved,
In the below program,
Code: |
%let text = lower case values;
%let val = %upcase(&text);
%put &val;
%let prog = %nrstr(%put &val);
&prog; |
I was expecting that the line 5 statement &PROG would get resolved to %put &val and then this %put statement would inturn produce "LOWER CASE VALUES" on log,
But I got the below resolution error message on the log,
Code: |
1 %let text = lower case values;
2 %let val = %upcase(&text);
3 %put &val;
LOWER CASE VALUES
4 %let prog = %nrstr(%put &val);
5 &prog;
NOTE: Line generated by the macro variable "PROG".
5 %put &val
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order. |
Could you please let me know why the &prog; is not producing "LOWER CASE VALUES".
I am not looking to correct the program or modify it somehow since this is only a self-learning exercise to undrstand the working,
but would like to understand how the values are resolved during execution and how this error occurs.
I read about Input stack then tokenisation then word processor of macro execution, but they sound greek and latin to a beginner :S
Thanks for viewing. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1743 Location: Tirupur, India
|
|
|
|
Hello Peter,
Thank you for the link,
But I am still not clear of the difference between the third line "%put &val;"
and the 5th line "&prog;" which inturn gets resolved to "%put &val;" (3rd line)
The 3rd line generates an output, but the 5th line does not :S
Regards, |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
The %NRSTR function prevents the & from triggering macro variable resolution. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1743 Location: Tirupur, India
|
|
|
|
Thanks Peter.
I think it makes sense now, I misunderstood the program thinking that the NRSTR was in effect with an argument only on one line and not on the next line in which refers the argument. |
|
Back to top |
|
|
|