|
You should be able to do this, I think:
data have;
infile datalines dsd missover;
input code: $;
datalines;
AB 237
AB 248A
CD 239 CC3
CD A48
AB 225 B
AB 225 #1
AB225
;
run;
data want;
set have;
code2 = prxchange('s/([A-Z]{2}) ?(\d{3}).*/$1 $2/',-1,code);
run;
-Joe
On Wed, Dec 10, 2008 at 10:53 AM, Sid N <nsid31@gmail.com> wrote:
> Hi,
>
> I am trying to use perl regular expressions to change/remove characters
> from
> my dataset, but have not been very successful. The sample data is provided
> below:
>
> data have;
> infile datalines dsd missover;
> input code: $;
> datalines;
> AB 237
> AB 248A
> CD 239 CC3
> CD A48
> AB 225 B
> AB 225 #1
> AB225
> ;
> run;
>
> I would like to remove characters based on the following conditions:
> 1. Remove the last character along with any leading spaces if the last
> character is a letter (as in AB 248A and AB 225 B). Desired output is AB
> 248
> and AB 225.
> 2. Remove any characters following a special character (along with the
> special character -- AB 225 #1). Desired output is AB 225.
> 3. Remove all characters beginning with the second set of alpha characters
> (CD 239 CC3 to CD 239).
>
> The final output I am looking for is:
> AB 237
> AB 248
> CD 239
> CD A48
> AB 225
> AB 225
> AB225
>
> Please note there are no space(s) in some values (example: AB225).
>
> Thanks in advance.
> Sid
>
|