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!
You are telling SAS that the single quote is a separator, so SAS obeys.
This works:
%let x=%scan(&whr,1,#);
You are telling SAS that the single quote is a separator, so SAS obeys.
This works:
%let x=%scan(&whr,1,#);
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".
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.