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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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