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;

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 852 views
  • 1 like
  • 2 in conversation