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

Hi, I'm trying to extract a text string (name) from a longer string, which may occur either once within the string or multiple times (several names). I'm breaking the longer string into groups and using prxparse and prxmatch with grouping to extract only the group I need, but something is not working. Below is an example of my text string, my code and what I'm looking for at the end.

 

data have; 

Prov_Info ="ProviderName: Spine and Pain Center of Whatchamikola; IDN: 2345678901; IsGroup: No;,   ProviderName: Happy Toes; IDN: 3456789012; IsGroup: No;,   ProviderName:  IDN: 3456789012; IsGroup: Yes;, ProviderName: Bright Smiles of AZ; IDN: 1234567890 IsGroup: Yes;, "; 

 

patternID = prxparse('/^(ProviderName:)( |.*; )(NPI: )/'); 

       if prxmatch(patternID, strip(Prov_Info)) then do;

     newname=prxposn(patternID, 2, Prov_Info);

end;

run;

 

Result needed:

newname=Spine and Pain Center of Whatchamikola; Happy Toes;  Bright Smiles of AZ;

 

Any suggestions would be attreciated.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

you may need to use prxnext. prxparse('/(ProviderName:\s+[a-zA-z ]+?;)/') indicates providers name folowed by space and words and till the ; prxnext capture position and length wherever you have this pattern. by doing substr(prov_info, position+13, length-13, we can remove ProviderName:

 

 

data have; 
Prov_Info ="ProviderName: Spine and Pain Center of Whatchamikola; 
IDN: 2345678901; IsGroup: No;,
ProviderName: Happy Toes; IDN: 3456789012; IsGroup: No;,
 ProviderName:  IDN: 3456789012; IsGroup: Yes;,
 ProviderName: Bright Smiles of AZ; IDN: 1234567890 IsGroup: Yes;, "; 
  run;
  
 


data want;
length val patternid $200.;
set have;
 start = 1;
   stop = length(prov_info);
 
   re = prxparse('/(ProviderName:\s+[a-zA-z ]+?;)/');
   set have;
   call prxnext(re, start, stop, trim(prov_info), position, length);
      do while (position > 0);
         val = substr(prov_info, position+13, length-13);
          patternID = catx(" ",  patternid, val);
         call prxnext(re, start, stop, trim(prov_info), position, length);
      end;
drop re start stop position length val;
run;

proc print data=want;
run;

 

View solution in original post

10 REPLIES 10
kiranv_
Rhodochrosite | Level 12

you may need to use prxnext. prxparse('/(ProviderName:\s+[a-zA-z ]+?;)/') indicates providers name folowed by space and words and till the ; prxnext capture position and length wherever you have this pattern. by doing substr(prov_info, position+13, length-13, we can remove ProviderName:

 

 

data have; 
Prov_Info ="ProviderName: Spine and Pain Center of Whatchamikola; 
IDN: 2345678901; IsGroup: No;,
ProviderName: Happy Toes; IDN: 3456789012; IsGroup: No;,
 ProviderName:  IDN: 3456789012; IsGroup: Yes;,
 ProviderName: Bright Smiles of AZ; IDN: 1234567890 IsGroup: Yes;, "; 
  run;
  
 


data want;
length val patternid $200.;
set have;
 start = 1;
   stop = length(prov_info);
 
   re = prxparse('/(ProviderName:\s+[a-zA-z ]+?;)/');
   set have;
   call prxnext(re, start, stop, trim(prov_info), position, length);
      do while (position > 0);
         val = substr(prov_info, position+13, length-13);
          patternID = catx(" ",  patternid, val);
         call prxnext(re, start, stop, trim(prov_info), position, length);
      end;
drop re start stop position length val;
run;

proc print data=want;
run;

 

Bluebonnet16
Fluorite | Level 6

That works! Thank you so very much, kiranv_!!!!

Bluebonnet16
Fluorite | Level 6
Hi,



The code works and does exactly what I need. However, I just realized, that if there is a comma in the provider name, a dot, or brackets, then it doesn't. 😞



Some of the examples, on which the code didn't work:



data have2;

Prov_Info ="ProviderName: Shapa Inc.;

IDN: 2345678901; IsGroup: No;, ProviderName: Smith, John; IDN: 3456789012; IsGroup: No;,

ProviderName: IDN: 3456789012; IsGroup: Yes;, ProviderName: Pharmacy TX-115; IDN: 1234567890 IsGroup: Yes;, ";

ProviderName: Star Med EMS (Medicare); IDN: 1234567890 IsGroup: Yes;, ";

ProviderName: CVS Pharmacy 50; IDN: 1234567890 IsGroup: Yes;, ";

ProviderName: CASE MANAGEMENT & IDN: 1234567890 IsGroup: Yes;, ";

run;



Please let me know if there is a solution to account for those special characters in the provider name? Thank you!


kiranv_
Rhodochrosite | Level 12

I guess ProviderName: CASE MANAGEMENT & IDN: 1234567890 IsGroup: Yes;, ";

should be like ProviderName: CASE MANAGEMENT & something; IDN: 1234567890 IsGroup: Yes;, ";

Bluebonnet16
Fluorite | Level 6
Yes, very unusually spelled provider name: ProviderName: MEDICAL CASE MANAGEMENT & SOCIAL SERVICES; IDN: 1234567890; IsGroup: Yes;,



Thank you!


kiranv_
Rhodochrosite | Level 12

one last question. Do you have numbers in providers name

ProviderName: CVS Pharmacy 50

if it does not then you can use.

 

 re = prxparse('/(ProviderName:\s+\D+?;)/');
Bluebonnet16
Fluorite | Level 6
Yes, unfortunately some provider names, like pharmacies for example, do contain digits in the name


kiranv_
Rhodochrosite | Level 12

this should work. i have used ?!IDN: ?! is negative lookahead, it will take everything till ; in providername unless IDN comes after providername and I guess this happens when you have no providername

 

re = prxparse('/(ProviderName:\s+(?!IDN:).+?;)/');
Bluebonnet16
Fluorite | Level 6
Yeap, it worked!! No missing values for the patternID 🙂



Thank you So SO SO very much!!!!


kiranv_
Rhodochrosite | Level 12

You are welcome and I am glad it worked

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 10 replies
  • 1517 views
  • 0 likes
  • 2 in conversation