Hello, Thank you all for the comments. I tried to recreate the sample but I ended up with many errors, instead I chose the first 30 samples, in ling format and not linked to other datasets. Instead I created a Github link:https://github.com/neyoushah/sashelp/blob/main/sashelp.sas7bdat As you can see my unlinked data has several visits per patient. So I thought we could say if.first patient_id and if.last. So now, one must find the number of visits which included at least one alcohol related code for each patient_id. The codes are as follows: data want; set dad ; array d D_I10_:; array c{25} $ 4 _temporary_ ('F103' 'F104' 'F105' 'F106' 'F107' 'F108' 'F109' 'F100' 'F101' 'F102' 'G621' 'G312' 'G721' 'I426' 'K292' 'K700' 'K704' 'K701' 'K702' 'K703' 'K709' 'K852' 'K860' 'Q860' 'P043'); do i= 1 to dim(d); if whichc(d[i],of c(*))>0 then do alcohol1='Chronic— Wholly attributable to alcohol'; leave; end; end; run;data home.w;
... View more