DATA Step, Macro, Functions and more

Call execute - list of values

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Call execute - list of values

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.*


Accepted Solutions
Solution
‎12-15-2017 05:20 PM
Super User
Posts: 22,844

Re: Call execute - list of values

[ Edited ]

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:

 

http://documentation.sas.com/?docsetId=sqlproc&docsetTarget=p0lsf4btafkw9mn1md4c69kkfwbl.htm&docsetV...

 

EDIT: And the CALL EXECUTE documentation does a good job of illustrating how to use it to call a macro. 

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1blnvlvciwgs9n0zcilud6d6ei9.htm&...

View solution in original post


All Replies
Super User
Posts: 13,023

Re: Call execute - list of values

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.

Solution
‎12-15-2017 05:20 PM
Super User
Posts: 22,844

Re: Call execute - list of values

[ Edited ]

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:

 

http://documentation.sas.com/?docsetId=sqlproc&docsetTarget=p0lsf4btafkw9mn1md4c69kkfwbl.htm&docsetV...

 

EDIT: And the CALL EXECUTE documentation does a good job of illustrating how to use it to call a macro. 

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1blnvlvciwgs9n0zcilud6d6ei9.htm&...

Super User
Posts: 6,537

Re: Call execute - list of values

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;

Super User
Super User
Posts: 7,847

Re: Call execute - list of values

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)
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 187 views
  • 1 like
  • 5 in conversation