Architecting, installing and maintaining your SAS environment

Need to Create y

Reply
N/A
Posts: 1

Need to Create y

Hi ,

I have a variable x. It contains string like

x

02p wed ssd values having alpha numeric

people having rty ers that udf

they have edf 234 bcd fgh

I need to Create y

y

02p wed ssd

rty ers udf

edf 234 bcd fgh

I need to pull length of 3 from the given string.

Can any once help me out on this.

Thanks,

sai

Super Contributor
Posts: 297

Re: Need to Create y

How about the following?

DATA WANT;

  SET HAVE;

  LENGTH Y $200 DONE 3;

  DO I = 1 BY 1 UNTIL (DONE);

  Y1 = SCAN(X,I);

  IF LENGTH(Y1) = 3 THEN Y = CATX(' ',Y,Y1);

  IF Y1 = '' THEN DONE = 1;

  END;

  DROP Y1 DONE;

RUN;

Respected Advisor
Posts: 3,124

Re: Need to Create y

You can also try PRX:

data x;

infile cards truncover;

input var $200.;

cards;

02p wed ssd values having alpha numeric

people having rty ers that udf 34

they have edf 234 bcd fgh t

;

data y;

  set x;

   new_var=prxchange('s/(\b[0-9a-zA-Z]{4,}\b)|(\b[0-9a-zA-Z]{1,2}\b)//i',-1, var);

run;

Haikuo

Ask a Question
Discussion stats
  • 2 replies
  • 334 views
  • 4 likes
  • 3 in conversation