BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a macro variable, which contains a list of character strings. I am wondering if there is any way to get a series of new macro variables from that. To illustrate with an example:

I have: %let old_list = a b c d ; * a, b, c, d are the variable names in my model;
I want following 3 new macro variables so that I can refit the model with new list:
%let new_list1 = b c d;
%let new_list2 = a c d;
%let new_list3 = a b c;


I really appreciate any help on getting this. Thanks.
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
This is more of a macro usage question than a stored process question. Your best bet for a solution might be to contact Tech Support for help with a more automated approach or possibly using a multiple value parameter for your stored process.

To "break down" the value in the old_list macro variable, you could use the SCAN function invoked with %SYSFUNC, as shown below:
[pre]
%let old_list = a b c d ;

%let v1 = %sysfunc(scan(&old_list,1));
%let v2 = %sysfunc(scan(&old_list,2));
%let v3 = %sysfunc(scan(&old_list,3));
%let v4 = %sysfunc(scan(&old_list,4));
%let v5 = %sysfunc(scan(&old_list,5));

%put --------> pieces of old_list &old_list;
%put --------> v1 = &v1;
%put --------> v2 = &v2;
%put --------> v3 = &v3;
%put --------> v4 = &v4;
%put --------> v5 = &v5;
%put ----> Note how v5 is "null" when you have reached;
%put ----> the end of the string contained in old_list;
[/pre]

To see how the SCAN function works, submit the above code from an EG code node or in a SAS Display Manager session. The results from the %PUT statements will appear in the SAS log. When you run this code snippet, you will see that I have created 5 separate macro variables -- &v1 thru &v4 have the values that were parsed out of &old_list and v5 is "null" because there was no 5th value in the string.

To really code a robust solution for your stored process so you can build multiple model statements, you will probably need a macro program and a macro %do loop (at the very least). Tech Support can help you with those. To contact Tech Support, refer to:
http://support.sas.com/techsup/contact/index.html

Good luck,
cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 750 views
  • 0 likes
  • 2 in conversation