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!
Use call execute from a pseudo dataset:
data _null_;
input string $;
call execute('%nrstr(%pleasehelp(' !! string !! ')););
datalines;
myvalue1
myvalue2
myvalue3
myvalue4
myvalue5
myvalue6
;
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?
That many data items will surely be kept in a dataset, so it's the same method. Just use that dataset instead of the datalines.
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 !! '));');
it is multiple obs with each obs to be fed through the macro 🙂
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;
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.