New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 7426 views
  • 0 likes
  • 5 in conversation