user601828
user601828

Reputation: 509

SAS Code for regular expression

I have an address string thats space delimited, I'm trying to replace the second argument with the third. The code I posted below doesn't work. Please help me correct it.

data sasuser.word_exchange;
set sasuser.testnew3;
retain re1 re2 ;
if _N_ = 1 then do;
re1 = prxparse('s/DR/DRIVE/');
re2= prxparse('s/AVE/AVENUE/');
end;
call prxchange( re1,-1, strip(CITYSTATE));
call prxchange( re2,-1, strip(CITYSTATE));
RUN;

Upvotes: 1

Views: 265

Answers (1)

Joe
Joe

Reputation: 63434

You can't use STRIP in that context. Here's an example using /io (i=case insensitive, o=compile once, so no need for the if n=1 block). 'i' may be undesirable depending on your data.

data have;
input @1 CITYSTATE $200.;
infile datalines truncover;
datalines;
2001 Bellini Ave Michigan City IN 58431
123 Anywhere Dr Boston MA 00123
456 Nowhere Lane New York City NY 10035
;;;;
run;

data want;
set have;
re1 = prxparse('s/DR/DRIVE/io');
re2= prxparse('s/AVE/AVENUE/io');
call prxchange( re1,-1, CITYSTATE);
call prxchange( re2,-1, CITYSTATE);
put CITYSTATE=;
RUN;

Upvotes: 1

Related Questions