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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.