DATA Step, Macro, Functions and more

help needed to create a macro var as x1 x2 ...xn where n is not determined

Reply
Occasional Contributor
Posts: 7

help needed to create a macro var as x1 x2 ...xn where n is not determined

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
Super Contributor
Posts: 345

Re: help needed to create a macro var as x1 x2 ...xn where n is not determined

You have tried using a loop?

[pre]%let varCount = 10;

%do i = 1 %to &varCount;
%local x&i;
%end;[/pre]
Occasional Contributor
Posts: 7

Re: help needed to create a macro var as x1 x2 ...xn where n is not determined

Posted in reply to andreas_lds
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
Regular Contributor
Posts: 171

Re: help needed to create a macro var as x1 x2 ...xn where n is not determined

[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]
Ask a Question
Discussion stats
  • 3 replies
  • 145 views
  • 0 likes
  • 3 in conversation