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

Hi 

I stored some where statements into a macro variable separated by '# ' and I'd like to scan the statement out one by one for deriving a new variable.
Below is a simple example but failed

%let whr=%str(TYPE eq 'A'#TYPE eq 'B'#TYPE eq 'C'#TYPE eq 'D');
%let x=%scan(&whr,1,'#');

%put &x;

When I tried to %put &x, only 'TYPE eq' was displayed in log.

Does anyone can give a hand? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You are telling SAS that the single quote is a separator, so SAS obeys.

 

This works:

 

%let x=%scan(&whr,1,#);

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

You are telling SAS that the single quote is a separator, so SAS obeys.

 

This works:

 

%let x=%scan(&whr,1,#);

 

Kurt_Bremser
Super User

Background: the macro language is a text processor and knows no other datatype, so quotes are not needed to identify strings. Instead they will become part of the "data".

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
  • 2 replies
  • 398 views
  • 0 likes
  • 3 in conversation