Help with Macro variable name var_%eval(&Tplevel-1)._id

Accepted Solution Solved
Reply
Super Contributor
Posts: 406
Accepted Solution

Help with Macro variable name var_%eval(&Tplevel-1)._id

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


Accepted Solutions
Solution
‎08-19-2014 08:43 PM
Super User
Posts: 5,497

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

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.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

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;

Super Contributor
Posts: 406

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

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

Super Contributor
Posts: 406

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

Thanks, Astounding.

I feel like so dump after reading your post.

Unbelievable.

HHC

Super User
Posts: 5,497

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

No problem.  Sometimes you just need an extra set of eyes.

Solution
‎08-19-2014 08:43 PM
Super User
Posts: 5,497

Re: Help with Macro variable name var_%eval(&Tplevel-1)._id

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 233 views
  • 3 likes
  • 3 in conversation