BookmarkSubscribeRSS Feed
mauley
Fluorite | Level 6

Sorry for posting this as I have looked at similar questions but cannot quite understand the method.

 

I have created a simple query and put this into a macro that I now intend to loop through using a list of values from a variable held in another data set as part of the filter.

 

%macro pleasehelp(myvalue) lets say myvalue is what will change in each loop through.

 

myvalue is a list of values stored in another data set.

 

I want to be able to do ;

 

%macro my_loop;

%do i=myvalue1 %to myvalue6;

 

%pleasehelp(&i);

%end;

%mend my_loop;

 

 

hope that makes sense and greatly appreciative of responses!

 

 

 

 

6 REPLIES 6
Kurt_Bremser
Super User

Use call execute from a pseudo dataset:

data _null_;
input string $;
call execute('%nrstr(%pleasehelp(' !! string !! ')););
datalines;
myvalue1
myvalue2
myvalue3
myvalue4
myvalue5
myvalue6
;
mauley
Fluorite | Level 6

thanks - what if my list of values was much greater than 6 and I wanted the solution to be dynamic so I didn't need to enter data lines?

Astounding
PROC Star

A more specific answer depends on the structure of the "other data set".  Does it contain one observation with a set of variables to feed the macro?  Does it contain a set of observations, each with one value to feed to the macro?

 

Also note, add a closing quote when you use @Kurt_Bremser 's solution:

 

call execute('%nrstr(%pleasehelp(' !! string !! '));');

 

mauley
Fluorite | Level 6

it is multiple obs with each obs to be fed through the macro 🙂

Astounding
PROC Star

So when @Kurt_Bremser says to use that data set instead of datalines, here's what that means:

 

data _null_;
set other_dataset;;
call execute('%nrstr(%pleasehelp(' !! variable_from_other_dataset !! '));');
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 720 views
  • 4 likes
  • 3 in conversation