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!
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 '^'
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 '^'
Thank you!
'%OBS' was exactly what I needed. I thought I had tried that but apparently not.
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.
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.
Ready to level-up your skills? Choose your own adventure.