BookmarkSubscribeRSS Feed
sainamit
Calcite | Level 5

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

2 REPLIES 2
Scott_Mitchell
Quartz | Level 8

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;

Haikuo
Onyx | Level 15

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

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

CLI in SAS Viya

Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 957 views
  • 4 likes
  • 3 in conversation