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

Hi. I am trying to drop all variables in a data set when the name ends with 'obs' (eg. ASQ2CM_A5obs  or ASQ60GM_C2obs) . Below is the code I am using:

 

proc contents data=out3 out=contents(keep=name) noprint ; run;
proc sql noprint ;
select name into :droplist separated by ' '
from contents
where upcase(name) like '%^OBS' escape '^'
;
quit;
data out4 ;
set out3 (drop=&droplist);
run;

 

But, I get the following error message

ERROR: Like pattern is not a valid pattern due to the invalid use of the escape pattern.

 

I know a similar question has been asked already but I am having trouble figuring out the escape pattern issue. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why do you have the ^ in your like string?

The only thing you can escape are the wildcards % and _ and the escape character itself.

 

So you either need

upcase(name) like '%^_OBS' escape '^'

to match names that end in _OBS

 

Or if you are using VALIDVARNAME=ANY then perhaps

upcase(name) like '%^^OBS' escape '^'

to match names that end in ^OBS

 

If you want to match a pattern of underscore then 0 or more characters and then OBS then use:

upcase(name) like '%^_%OBS' escape '^'

If you only want it match when there are exactly 5 characters after the _ then use:

upcase(name) like '%^___OBS' escape '^'

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why do you have the ^ in your like string?

The only thing you can escape are the wildcards % and _ and the escape character itself.

 

So you either need

upcase(name) like '%^_OBS' escape '^'

to match names that end in _OBS

 

Or if you are using VALIDVARNAME=ANY then perhaps

upcase(name) like '%^^OBS' escape '^'

to match names that end in ^OBS

 

If you want to match a pattern of underscore then 0 or more characters and then OBS then use:

upcase(name) like '%^_%OBS' escape '^'

If you only want it match when there are exactly 5 characters after the _ then use:

upcase(name) like '%^___OBS' escape '^'

 

SarahBOtto
Calcite | Level 5

Thank you!

 

'%OBS' was exactly what I needed. I thought I had tried that but apparently not.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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