BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5
%let name=ABCD efgh,ijkl mnop,qrst;

%put. %scan(&name,1, ,);


How to derive first delimiter string see below..

ABCD efgh


4 REPLIES 4
Patrick
Opal | Level 21

%let name=ABCD efgh,ijkl mnop,qrst;
%put %scan(%nrbquote(&name),1,%nrbquote(,));

Ksharp
Super User
%let name=ABCD efgh,ijkl mnop,qrst;

%put %scan(%bquote(&name),1,%(,));
Quentin
Super User

@Ksharp I think you're missing the STR.  As written:

%scan(%bquote(&name),1,%(,));

would treat four characters as delimiters: % ( )  ,

It works because the () are enough to hide the comma from the macro processor during the macro call.  But if the string has % or () in it, those characters will be delimiters.

 

1 %let name=ABCD% ef(gh,ijkl m)nop,qrst;
2 %put %scan(%bquote(&name),1,%(,));
ABCD

But with %STR(), it treats only one character as a delimiter: ,

 

3 %put %scan(%bquote(&name),1,%str(,));
ABCD% ef(gh

 

 

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.
Ksharp
Super User

Yeah. I am sure I write %STR ,

%put %scan(%bquote(&name),1,%str(,));

But I don't know why it would appear this. Maybe this forum eat 'STR' .

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
  • 856 views
  • 3 likes
  • 4 in conversation