BookmarkSubscribeRSS Feed
BobHope
Quartz | Level 8

I am facing a problem with macro variable naming. I couldn't figure out what do you call situations like this but I have attached a sample code.

The issue is that I need to get the variable model on the data foo to resolve to the macro variable model_&&multi&i.

I have tried almost everything I can come up with(&&model_&&multi&i,&&&model_&&multi&i etc.), but probably my limited under the hood knowledge on macro variables is the issue.


4 REPLIES 4
Kurt_Bremser
Super User

Have you tried doing it in stages?

like

%let helpvar=&&multi&i;

and then

&&model_&helpvar

If you break it into several steps, you can inspect the contents of the variables with %put, or use options symbolgen;

BobHope
Quartz | Level 8

Thanks for your answer. In fact I did try that also, did not work. Gives me resolve error in log.

Kurt_Bremser
Super User

See this:

%let model_testx=some_content;

%let multi1=testx;

%let i=1;

%put &&multi&i;

%let helpvar=&&multi&i;

%put &&model_&helpvar;

The last %put shows some_content.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not knowing exactly what you are trying to achieve why not something like:

proc sql;                              /* Create a dataset which has you loop values (so this &n_multi) */

     create table LOOP as

     select     distinct

                   NAME

     from       ...;

quit;

data _null_;                         /* Using the dataset you created above, generate a bit of code for each observation in that dataset

                                                  with the code and the loop variable */

     set loop;

     call execute('data foo;

                              model="'||strip(name)||'";

                          run;');

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 830 views
  • 0 likes
  • 3 in conversation