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



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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