BookmarkSubscribeRSS Feed
BETO
Fluorite | Level 6

Hi I have a comment box that looks like this 

Arrive 11/16/15   ticket #012345678 prod Id 45678

I need to just get the ticket#  which is the 8 digits ...I need output to be 012345678.. I use compress an it combine it together. .. I read up on prxchange  to extract but it's not working  thanks for your assistance 

Data table1;

Set table1;

Ticket =prxchange ("S/[^0-9]//",-1,text);

 

6 REPLIES 6
Astounding
Opal | Level 21

If you can rely on the first # being before the ticket number, it's easy:

 

data want;

set have;

length ticket $ 8;

ticket = scan(text, 2, '#');

run;

 

If you actually need 9 digits instead of 8 (you have 9 in your example), just change the length to $ 9.

 

Good luck.

Steelers_In_DC
Barite | Level 11

Similar solution but if I understand you correct you want another scan() in there:

 

data have;
infile cards dsd dlm='*****';
informat field $100.;
format field $100.;
input field$;
cards;
Arrive 11/16/15   ticket #012345678 prod Id 45678
;
run;

data want;
set have;
want = scan(scan(field,2,'#'),1);
run;

Astounding
Opal | Level 21

Steelers,

 

That's the purpose of having the LENGTH statement.  There's only room to hold 8 characters in the new variable, so you don't have to worry about getting rid of extra characters with an additional SCAN function.

 

It does require that the ticket numbers are 8 characters long, however.  (7 would be OK too, if the 8th character is a blank.)

BETO
Fluorite | Level 6
Hi Steelers it worked great but I do have a question the output has a semi colon :it's looks like this :012345678 I need the out put to be 012345678 ... thanks
Astounding
Opal | Level 21

Is there a colon in the incoming text, after the # ???

slchen
Lapis Lazuli | Level 10

It is easy to get number with scan here, if you want to use regular expression, try this.

 

data _null_;
string="Arrive 11/16/15   ticket #012345678 prod Id 45678";
number=prxchange('s/.*(?<=#)(\d+).*/$1/',-1,string);
put number;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1874 views
  • 1 like
  • 4 in conversation