I have two variables patid ( patient ID) and dx1 (code).
For all patient id (patid) I want only those dx1 where dx1 start with with '380' or '470' OR dx1 is equal to '98006'
and replace any other dx1 with missing.
Please find below the SAS code -
data abc;
infile datalines ;
input patid dx1 $ ;
datalines;
123 38000
122 47001
123 38010
124 78011
125 47021
126 47031
127 38005
128 98006
;
run;
data abc1;
set abc;
if upcase(substr(dx1,1,3)) not in ('380','470')
or
upcase(dx1) not in ('98006') then dx1 = '';
run;
The result is -
dx1 missing for all patid.
Why is that happening?