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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1331 views
  • 1 like
  • 4 in conversation