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.
Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.
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.