Help using Base SAS procedures

Need help in Finding a sub string which is in a particular format

Reply
Contributor
Posts: 45

Need help in Finding a sub string which is in a particular format

Hello,

I have a character string  which contains the words with the combination of characters, numbers and special character.

Now I would like to find/extract only the particular string which is in below mentioned format.

Input string :  " 10% discount to be given to accidental insurance customers in 9874-04562 on a pro rata basis"

Output Sub string  : 9874-04562

Thanks in advance.

SAS Employee
Posts: 15

Re: Need help in Finding a sub string which is in a particular format

You can use regular expressions:

data _null_;

   if _N_ = 1 then

   do;

      retain rId;

      rId = prxparse('/\d{4}-\d{5}/');

   end;

   str = ' 10% discount to be given to accidental insurance customers in 9874-04562 on a pro rata basis';

   call prxsubstr(rId, str, pos, len);

   if pos ^= 0 then

   do;

      match = substr(str, pos, len);

      put match=;

   end;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 182 views
  • 0 likes
  • 2 in conversation