BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sam369
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

You can accomplish the same thing without the strip by looking for a string containing only spaces.

where prxmatch('#/|^\s+$#o', var);

View solution in original post

7 REPLIES 7
FriedEgg
SAS Employee

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);

sam369
Obsidian | Level 7

Thank you FriedEgg, i am under learning curve. i would like to achieve that using regular expression

Thanks

Sam

FriedEgg
SAS Employee

A good thing to learn would be that this is an inefficient use-case for regular expression.

Haikuo
Onyx | Level 15

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;

FriedEgg
SAS Employee

You can accomplish the same thing without the strip by looking for a string containing only spaces.

where prxmatch('#/|^\s+$#o', var);

sam369
Obsidian | Level 7

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

FriedEgg
SAS Employee

\/|^\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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2745 views
  • 7 likes
  • 3 in conversation