BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
West26
Obsidian | Level 7

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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

 

West26
Obsidian | Level 7

Hello Chris,

I do appreciate for the quick response. It resolved the issue.

 

Thank you.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1056 views
  • 0 likes
  • 2 in conversation