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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.