08-19-2014 06:36 PM
Hi Everyone,
I get stuck with the name of variable built on a macro variable.
Basically, I have a macro variable Tplevel which take value of say 4, 5, 6.
I have variable call exit_to_4, exit_to_5.
For the Tplevel=6, I want to run:
do j=exit_to_5_id to nobs ;
I translate that into macro below and the name is not valid.
do j=exit_to_%eval(&Tplevel-1)._id to nobs ;
Could you please help me with that?
Thanks so much.
HHC
08-19-2014 08:43 PM
While it's worth considering whether there are easier, more direct ways to accomplish what you need, your code is very close. Just remove the dot after the closed parenthesis.
08-19-2014 06:59 PM
You may be better off creating a temporary macro variable outside of the data step assuming you are looping through values
Mixing macro functions in datasteps is often hard to resolve as wanted.
%let temp=exit_to_5%eval(&tplevel-1)_id;/* BEFORE the called datastep*/
...
do j=&temp to nobs;
08-19-2014 08:45 PM
Thanks for letting me know.
Actually, I am more curious to know how SAS handles it.
Of course I can get around with 2 macro variables say (X=5, Y=4).
HHC
08-19-2014 09:19 PM
Thanks, Astounding.
I feel like so dump after reading your post.
Unbelievable.
HHC
08-19-2014 11:13 PM
No problem. Sometimes you just need an extra set of eyes.
08-19-2014 08:43 PM
While it's worth considering whether there are easier, more direct ways to accomplish what you need, your code is very close. Just remove the dot after the closed parenthesis.
Need further help from the community? Please ask a new question.