Hello
Let's say that a user defined a parameter
%let x=1801 1802 1803 1804 1805 1806;
The task is to create another parameter called new2 that get value:
1801,1802,1803,1804,1805,1806
(As you can see instead of space there should be a comma)
Use the translate() function:
%let x=1801 1802 1803 1804 1805 1806;
data _null_;
x1 = translate("&x",","," ");
call symputx('x1',x1);
run;
%put x1=&x1;
Why? In() accepts both a comma and space delimited list. And you would want to write whole blocks of macro code to loop over a list as that would be messy and time consuming. Far easier to use by grouping if needed. If commas really are necessary, then just ask the user to add commas?
One way to go:
%let x=1801 1802 1803 1804 1805 1806;
%let new2=%sysfunc(prxchange(s/\b\s+\b/%nrbquote(,)/oi,-1,%nrbquote(&x)));
%put &=new2;
Note that comma-separated lists turn into a major PITA if you have to use them as macro parameters.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.