BookmarkSubscribeRSS Feed
sarkar_kanchan
Calcite | Level 5

Hi All,

Please help me to find out the solution for this ...

Comment is my variable ... i would like to extract only the Digit from the comment .For example  from the first line i need to extract 150 and from the second i want to extract 100 and so on .I tried with anydigit option but its not working as it only show 1 or 0 if there is any digit in the below comment.My date set large and have more than 10000 comments like this .

43534-PP - ABCDEF 150 ABC ABCD

07052-TT - ABCD 100 ABCDEFG

83092-DD -   ABCDEFG  540 ABCDEFRGTH

Regards

kanchan

4 REPLIES 4
Haikuo
Onyx | Level 15

This seems working on your as-is data:

DATA TEST;

     INFILE CARDS TRUNCOVER;

     INPUT VAR $100.;

     DIGITS=prxchange('s/^\d+\D+|\D+$//o',-1,var);

     CARDS;

43534-PP - ABCDEF 150 ABC ABCD

07052-TT - ABCD 100 ABCDEFG

83092-DD -   ABCDEFG 540 ABCDEFRGTH

;

Haikuo

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or just use scan, nice one xia keshan.

Alternatively, without perl:

data test;

  infile cards truncover;

  input var $100.;

  digits=compress(scan(var,3,'-'),' ','a');

cards;

43534-PP - ABCDEF 150 ABC ABCD

07052-TT - ABCD 100 ABCDEFG

83092-DD -   ABCDEFG 540 ABCDEFRGTH

;

run;

Ksharp
Super User

DATA TEST;

     INFILE CARDS TRUNCOVER;

     INPUT VAR $100.;

     DIGITS=scan(var,2,,'kd');

     CARDS;

43534-PP - ABCDEF 150 ABC ABCD

07052-TT - ABCD 100 ABCDEFG

83092-DD -   ABCDEFG 540 ABCDEFRGTH

;

run;

Xia Keshan

Haikuo
Onyx | Level 15

Nice. Never see 'kd' option in SCAN(). Thanks for sharing!

Well in this case, depending on OP's rules, DIGITS=scan(var,-1,,'kd'); will also be OK.

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
  • 4 replies
  • 684 views
  • 1 like
  • 4 in conversation