BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

Let's say that a user defined a parameter

%let x=1801 1802 1803 1804 1805 1806;

 

The task is to create another parameter called new2 that get value: 

1801,1802,1803,1804,1805,1806

 

(As you can see instead of space there should be a comma)

 

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why?  In() accepts both a comma and space delimited list.  And you would want to write whole blocks of macro code to loop over a list as that would be messy and time consuming.  Far easier to use by grouping if needed.  If commas really are necessary, then just ask the user to add commas?

Patrick
Opal | Level 21

@Ronein

One way to go:

%let x=1801 1802  1803   1804 1805 1806;
%let new2=%sysfunc(prxchange(s/\b\s+\b/%nrbquote(,)/oi,-1,%nrbquote(&x)));
%put &=new2;
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
  • 4 replies
  • 1304 views
  • 1 like
  • 4 in conversation