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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1106 views
  • 0 likes
  • 2 in conversation