BookmarkSubscribeRSS Feed
RaviKommuri
Fluorite | Level 6

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.

1 REPLY 1
Vladislaff
SAS Employee

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 817 views
  • 0 likes
  • 2 in conversation