BookmarkSubscribeRSS Feed
shubham1
Calcite | Level 5

Hello

 

I have a  macro varible whose value can be like this 

 

%let x='a''b';

%letx='ab''bc';

%letx='a''b''c';

 

what I want is have spaces between words

my output should be

1st one ='a'  'b'

2nd one='ab'  'bc'

3rd one ='a'  'b'  'c'

 

how can i achieve this 

 

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

And you still want it in a macro variable?

shubham1
Calcite | Level 5

not really 

what my aim is that I want to extract each word and then apply scan function 

for example  in this case 

%let x='a''b'

once i get the value as 'a'  'b' the i can easily apply scan function and extact 'a' and 'b' separately 

 

Jagadishkatam
Amethyst | Level 16

you can extract from within the macro variable as well as below

 

%let x=%sysfunc(scan('a''b',2,''));
%put &x;
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

Please try as below

 

%let x=%sysfunc(tranwrd('a''b','',' '));
%put &x;
Thanks,
Jag

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 16. 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
  • 4 replies
  • 604 views
  • 1 like
  • 3 in conversation