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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 1980 views
  • 7 likes
  • 3 in conversation