BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BogdanC
Fluorite | Level 6

I have three macro variables that contai some dynamic values - the number of values or the values themselves may change in the script flow.

 

 

 

%let x = 1 2 5;
%let y = 10 15;
%let z = 5 15 25 60 80;

 

 

I need to create all possible combinations out of these variables and save the data - it would contain 3*2*5 = 30 rows. I looked at proc plan and it doesn't seem to ba able to do this, not directly at least. Also tried this:

 

data GridSearch;
do a = SYMGET('x');
do b = SYMGET('y');
do c = SYMGET('z');
output;
end;
end;
end;
run;

Apparently this is not the correct way to reference maro varaible as it returns the as text rather than lsit of values. 

 

 

Any ideas?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, to answer your question first, do loops need to, when a list of values is provided, be separated by commas not spaces:

%let x = 1,2,5;
%let y = 10,15;
%let z = 5,15,25,60,80;

data GridSearch;
 do a = &x.;
   do b = &y.;
     do c = &z.;
       output;
     end;
   end;
 end;
run;

Now, from my side, I would increment the indentation for each loop to make the code readable.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, to answer your question first, do loops need to, when a list of values is provided, be separated by commas not spaces:

%let x = 1,2,5;
%let y = 10,15;
%let z = 5,15,25,60,80;

data GridSearch;
 do a = &x.;
   do b = &y.;
     do c = &z.;
       output;
     end;
   end;
 end;
run;

Now, from my side, I would increment the indentation for each loop to make the code readable.

Ksharp
Super User

%let x = 1 2 5;
%let y = 10 15;
%let z = 5 15 25 60 80;

data want;
 do x=%sysfunc(translate(&x,%str(,),%str( )));
  do y=%sysfunc(translate(&y,%str(,),%str( )));
   do z=%sysfunc(translate(&z,%str(,),%str( )));
    output;
   end;
  end;
 end;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1767 views
  • 1 like
  • 3 in conversation