Hello
I have a macro varaible called My1 with values X Y Z
I want to create a new macro variable called My2 based on My1 macro variable that will get values 'X' 'Y' 'Z'
%let My1=X Y Z;
/**Want to calculate a new macro var called My2 get values 'X' 'Y' 'Z'
Use a DATA step (simpler code).
Define a maximum length (32767) character variable.
Proceed through the macro variable (COUNTW and SCAN functions), use the QUOTE function to add the single quotes, and CATX to store the results in the new variable.
CALL SYMPUTX to create the new macro variable.
@Kurt_Bremser just gave you the best advice that anyone can give about the macro language. Don't use it when there is a simpler alternative such as DATA step processing.
Use the basePlus package's %zipEvalf() macro:
%loadPackage(BasePlus)
resetline;
%let My1=X Y Z;
%let My2 =%zipEvalf(&My1., %str(%'), function=quote);
%put &=my1. &=my2.;
Bart
Here one way to go
%let My1=X Y Z;
%let My2=%sysfunc(prxchange(s/(\w+)/'$1'/i,-1,&My1));
%put &=My2;
69 %let My1=X Y Z; 70 %let My2=%sysfunc(prxchange(s/(\w+)/'$1'/i,-1,&My1)); 71 %put &=My2; MY2='X' 'Y' 'Z'
Take a look at Richard DeVenezia's %seplist() utility. It will do that and more. https://www.devenezia.com/downloads/sas/macros/index.php?m=seplist
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.