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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 303 views
  • 1 like
  • 2 in conversation