BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stataq
Quartz | Level 8

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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;
The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

View solution in original post

1 REPLY 1
Quentin
Super User

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;
The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 614 views
  • 1 like
  • 2 in conversation