Hi all,
Does anyone know how to define a list of values (for example, the values of two different columns in a table) into a macro variable using call execute?
Thanks,
L.*
CALL EXECUTE is designed to avoid exactly that situation....more details are needed.
PROC SQL will create lists of macro variables from a table. In general, that's the easiest way:
EDIT: And the CALL EXECUTE documentation does a good job of illustrating how to use it to call a macro.
Perhaps you should expand on what you are doing with those macro variables. Since you are using a dataset apparently if you do nothing else with the call execute facility in the data step you use call execute the result will likely only have the values from the last record of the data set.
If you are generating other code with call execute then you would use the values more or less directly in the call execute statements.
So I am not seeing the advantage of attempting to use call execute to create macro variables.
CALL EXECUTE is designed to avoid exactly that situation....more details are needed.
PROC SQL will create lists of macro variables from a table. In general, that's the easiest way:
EDIT: And the CALL EXECUTE documentation does a good job of illustrating how to use it to call a macro.
Notice that this is such a bad idea that nobody bothered to ask what you want your list to look like. You really didn't specify where you want commas, quotes, or what the order should be when using two columns. Just in case you really need to do it this way (doubtful), here is how you would do it with a single column (assumed here to be a character variable).
%global list;
data _null_;
set many_columns;
call execute('%let list = &list ' || column_1 || ';' ) ;
run;
CALL EXECUTE() just takes a string and pushes it onto the stack for SAS to run after the current step ends. You ned to explain your actual problem in more detail to get a solution.
To concatenate values into strings in a datastep use one of the many CAT....() functions.
For example if you had five variables named VAR1 to VAR5 and you wanted to make a comma separated list of the values you could use.
catx(',',of var1-var5)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.