Hello,
The below resolution from our community, works perfectly for macro variables separated by blanks
%let mvar=aaaaa bbbbb ccccc zzzzz;
%let mvar_quotes=%nrbquote(')%qsysfunc(prxchange(s/\s+/%nrbquote(',')/oi,-1,&mvar))%nrbquote(');
%put mvar_quotes: %bquote(&mvar_quotes);
resolution:
mvar_quotes: 'aaaaa','bbbbb','ccccc','zzzzz'
But I do have the %let as
%let mvar=aa-aa-a,bbbb-b,c-cccc,zzz-zz (where the variables are alreadu seperated by a ',')
I need quotes for the variables separated by ',' which means I need the resolved macro variables like beow.
mvar_quotes: 'aa-aa-a','bbbb-b','c-cccc','zzz-zz'
I have tried modifying the above resolution stmt, but couldn't succeed. Pls help
This will work whether the separator is a space or a comma:
%let mvar=aa-aa-aaaaaaaa bbbb-b,c-cccc,zzz-zz;
%let list = %str(%')%qsysfunc(prxchange(%str(s/\s|,/','/),-1,%superq(mvar)))%str(%');
%let list = %unquote(&list);
data T; do A=&list.; putlog A=; end; run;
A=aa-aa-aaaaaaaa
A=bbbb-b
A=c-cccc
A=zzz-zz
This will work whether the separator is a space or a comma:
%let mvar=aa-aa-aaaaaaaa bbbb-b,c-cccc,zzz-zz;
%let list = %str(%')%qsysfunc(prxchange(%str(s/\s|,/','/),-1,%superq(mvar)))%str(%');
%let list = %unquote(&list);
data T; do A=&list.; putlog A=; end; run;
A=aa-aa-aaaaaaaa
A=bbbb-b
A=c-cccc
A=zzz-zz
Hello Chris,
I do appreciate for the quick response. It resolved the issue.
Thank you.
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.