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".
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.