sas - split string to columns with content fill -


i have data looks this:

id    sequence --------------------------------- 101   e6s,k11t,q174k,d177e 102   k11t,v245ekq 

i need add:

  1. a new column column heading each sequence, add prefix 'rt', drop letters following numeric part of sequence
  2. fill new column letters follow numeric part of sequence

i need create this:

id    sequence                rte6   rtk11   rtq174   rtd177   rtv245 ----------------------------------------------------------------------- 101   e6s,k11t,q174k,d177e    s      t       k        e 102   k11t,v245ekq                   t                         ekq 

i assume want sas data set , not report. anydigit makes pretty easy find last non-digit sub-string.

data seq;    infile cards firstobs=3;    input id:$3. sequence :$50.;    cards; id    sequence --------------------------------- 101   e6s,k11t,q174k,d177e 102   k11t,v245ekq ;;;;    run; proc print;    run; data seq2v / view=seq2v;    set seq;    length w name sub $32 subl 8;    = 1 1;       w = scan(sequence,i,',');       if missing(w) leave;       subl = anydigit(w,-99);       name = substrn(w,1,subl);       sub = substrn(w,subl+1);       output;       end;    run; proc transpose data=seq2v out=seq3(drop=_name_) prefix=rt;    id sequence;    var sub;    id name;    run; proc print;    run; 

enter image description here


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -