SAS makes it easy to test if the beginning of a string matches. Use the colon modifier on the comparison operator.
if code =: 'F10'
To summarize a patient you can use the fact that boolean expression evaluate to 0 or 1.
select patient
,sum(code =: 'F10') as alcohol
,sum(code =: 'F40') as phobic
from have
group by patient
;
... View more