Easy enough, but study the code so that you can make such changes/additions on your own:
data want;
set have;
if substr(LESNID,1,2) in ('R1','R2') then prefix='TL';
else if substr(LESNID,1,2) eq 'R3' then prefix='NT';
else if substr(LESNID,1,2) eq 'R4' then prefix='NL';
run;
data want (drop=counter prefix);
set want;
array assigns(999) _temporary_;
by SUbJID prefix notsorted;
if length(LESNID) gt 4 then do;
converted=catt(prefix,substr(LESNID,4,2));
end;
else do;
if first.prefix then do;
counter=1;
call missing(of assigns(*));
assigns(input(substr(LESNID,2),8.))=counter;
end;
else if missing(assigns(input(substr(LESNID,2),8.))) then do;
counter+1;
assigns(input(substr(LESNID,2),8.))=counter;
end;
converted=catt(prefix,put(assigns(input(substr(LESNID,2),8.)),z2.));
end;
run;
Art, CEO, AnalystFinder.com
... View more