BookmarkSubscribeRSS Feed
sunrain
Calcite | Level 5
Dear Helper:

I am trying to create a macro var as x1 x2 ...xn, where the number n should be determined by another macro var.

Sunrain
3 REPLIES 3
andreas_lds
Jade | Level 19
You have tried using a loop?

[pre]%let varCount = 10;

%do i = 1 %to &varCount;
%local x&i;
%end;[/pre]
sunrain
Calcite | Level 5
Thank you, Andrea.
I would like a macro var to contain these variable names, not a list of macro vars.
Sorry that I misled you.

Sunrain
polingjw
Quartz | Level 8
[pre]
22 %macro varlist(varCount);
23 %do i=1 %to &varCount;
24 %*; x&i
25 %end;
26 %mend;
27 %let var=%varlist(10);
28 %put var=&var;
var=x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
[/pre]

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
  • 3 replies
  • 799 views
  • 0 likes
  • 3 in conversation