BookmarkSubscribeRSS Feed
saspert
Pyrite | Level 9

HI,

My input field is something like this -

 

ALICE REV 2-KY/CB 

ALICE-REV 2/BHP
Audition/BTT
Audition-CK/BT

 

and my output field needs to be somehting like this -

ALICE

Audition

 

I have a vague idea about PRX functions. Any help will be appreciated.

 

Thanks,

saspert

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Have a go with this sample, check the doc for the Tables of Perl Regular Expression (PRX) Metacharacters

 

data want;
  infile cards ;
  input text $64.;

  wordEnd = prxmatch("/\W+\b/", text);
  word = substr(text, 1, wordEnd-1);
  putlog _all_;
cards;
ALICE REV 2-KY/CB 
ALICE-REV 2/BHP
Audition/BTT
Audition-CK/BT
;

Bruno

Astounding
PROC Star

If you know the delimiters that might appear in your data, you can code this simply:

 

data want;

set have;

string = scan(string, 1, '- /');

run;

 

Be sure to include a blank as one of the delimiters.

slchen
Lapis Lazuli | Level 10


proc sql;
select distinct(prxchange('s/(^\w+)\W+?.*/$1/i',1,text)) as string from want;
quit;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1020 views
  • 6 likes
  • 4 in conversation