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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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