And
if sum(drug1,drug2,drug3)=1 then do;
if drug1 = 1 then drugtypes = 1;
else if drug2 = 1 then drugtypes = 2;
else if drug3 = 1 then drugtypes = 3;
end;
could be replaced with
if sum(drug1,drug2,drug3)=1 then drugtypes= whichn(1,drug1,drug2,drug3);
The Whichn, and the companion Whichc for character variables, returns the order number of the first variable/value that is equal to the first value parameter. Consider if you had 10 drug variables, that would be a fair number of IF/Then/Else but the difference with whichn would be to just add the variables to list.
Plus if the variables are in an Array you can use Whichn(<value>, of arrayname(*)) which makes this even shorter for long lists of variables.
... View more