Hello,
I would like to get var list that start with certain pattern from sample data. for example, variables start with 'Cr'. Currently I have following codes, but I was not able to utilize the macro variable that was set up for pattern, Could anyone tell me what I did wrong?
```
proc contents data=sashelp.baseball noprint out=_contents_;
run;
%let np=Cr; /*macro variable for name pattern*/
data _contents1_;
set _contents_(where=(upcase(name)=:'&np.'));
run;
```
I tried "&np." and &np. and they are also not working.
Thanks.
Macro variables don't resolve inside single quotes; you need to use double quotes.
Since you are upcasing name you need to search for an uppercase "CR". Try:
%let np=Cr; /*macro variable for name pattern*/
data _contents1_;
set _contents_(where=(upcase(name)=:"%upcase(&np)"));
run;
Macro variables don't resolve inside single quotes; you need to use double quotes.
Since you are upcasing name you need to search for an uppercase "CR". Try:
%let np=Cr; /*macro variable for name pattern*/
data _contents1_;
set _contents_(where=(upcase(name)=:"%upcase(&np)"));
run;
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 save with the early bird rate—just $795!
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.