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
PROC Star

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
PROC Star

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
PROC Star

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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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