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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
ballardw
Super User

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.

Reeza
Super User

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

Astounding
PROC Star

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;

Tom
Super User Tom
Super User

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)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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