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

Team,

 

I have this and it works fine:

%let have = 1 2 3;
%let want = %sysfunc(tranwrd(%quote(%trim(&have)),%str( ),%str(,)));
%put want=&want.;

But if the user put more than one space between the numbers then it comes up as 1,2,,,3.

 

The above code will not work for:

%let have = 1 2     3;
%let want = %sysfunc(tranwrd(%quote(%trim(&have)),%str( ),%str(,)));
%put want=&want.;

Please advise.

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try

 

%let have =%sysfunc(compbl( 1 2     3));
%let want = %sysfunc(tranwrd(%quote(%trim(&have)),%str( ),%str(,)));
%put want=&want.;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Try

 

%let have =%sysfunc(compbl( 1 2     3));
%let want = %sysfunc(tranwrd(%quote(%trim(&have)),%str( ),%str(,)));
%put want=&want.;
data_null__
Jade | Level 19
Why do you need to add commas?
david27
Quartz | Level 8

These numbers go inside an in statement. if number in (1,2,3). User may also not pass any value to the macro.

ballardw
Super User

@david27 wrote:

These numbers go inside an in statement. if number in (1,2,3). User may also not pass any value to the macro.


The SAS IN operator does not require commas any more though it used to.

Also for INTEGER values a SAS IN comparison can use a range indicated with a colon: Number in (1:3); is the same as Number in (1 2 3) or Number in (1,2,3).

david27
Quartz | Level 8

Thank You team for the responses.

 

I just learnt about the in operator not requiring comma(,) within parenthesis ACCIDENTALLY just today(because of a programming mistake i did).

By the way---From when did it change?

Tom
Super User Tom
Super User

I have never had to use commas with the IN operator.

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 7878 views
  • 0 likes
  • 5 in conversation