Hi All,
I have thousands of different string in variable "var". I want to pick only those records having (/ or missing)
data have;
input grp $40. var $20.;
cards;
AAAAA Par_diff
BBBB rag*diff
CCCC rAg/diff
DDDD
EEEEE run_diF
;
run;
want: records with var (/,missing)
output:
CCCC rag/diff
DDDD
i am using
prxmatch("m/ragdiff/io",compress(var,'/'))>0 & Missing(var)
Thanks
Sam
You can accomplish the same thing without the strip by looking for a string containing only spaces.
where prxmatch('#/|^\s+$#o', var);
You main issue is having 'and' where it should be 'or.' I would not recommend using the regular expression, given your example (which I would also rewrite as prxmatch('#/|^\s+$#o', var) given your explained requirements).
where index(var, '/') or missing(var);
Thank you FriedEgg, i am under learning curve. i would like to achieve that using regular expression
Thanks
Sam
A good thing to learn would be that this is an inefficient use-case for regular expression.
Well, this seems working for me , it came to me as a surprise:
data have;
input grp :$40. var :$20.;
cards;
AAAAA Par_diff
BBBB rag*diff
CCCC rAg/diff
DDDD .
EEEEE run_diF
;
run;
data want;
set have;
if prxmatch('/\/|^$/', strip(var))>0;
run;
You can accomplish the same thing without the strip by looking for a string containing only spaces.
where prxmatch('#/|^\s+$#o', var);
Thanks to both!!! Work like champ!!!!
COuld you please explain what special character matches (/) & space? From the variable var....In the above regular expression
Thanks
sam
\/|^\s+$
Match either the regular expression below (attempting the next alternative only if this one fails) «\/»
Match the character “/” literally «\/»
Or match regular expression number 2 below (the entire match attempt fails if this one fails to match) «^\s+$»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.