No code, but some comments. This looks like Medicare billing data since there is a limit of 10 diagnoses. The size of some of these datasets can be huge, so some approaches (like TRANSPOSE) that are effective for smaller datasets run out of computer resources with larger ones.
ICD codes are character strings, not numbers, so trying to specify a range is tricky (e.g. ICD 345.1 is different from ICD 345.10). If you are just interested in the summary at the first three digits, use the SUBSTR function or the =: operator for the comparison, e.g.
IF diag1 =: '345' | diag1=:'346'...
or
SELECT ...
WHERE substr(diag1,1,3) IN ('345', '346', '296') | ...