To start with, you need to restructure your dataset as it is very difficult to achieve your goal with the present structure. You should have 2 columns, 'Prep' and 'Strength', containing the relevant values, instead of the QSN and Value columns. It will then be much easier to summarise. The code below gives you output identical to yours, however I suggest if you have more than the 3 value types in your example then you wrap the calculation part inside a macro. data have1; input ID QSN $ VALUE $; cards; 1 Prep Zov 1 Prep Pan 1 Prep Dol 1 Strength 50 1 Strength 50 1 Strength 100 2 Prep Zov 2 Prep Zov 2 Prep Zov 2 Strength 55 2 Strength 50 2 Strength 60 run; /* restructure dataset */ data temp1; set have (where=(qsn='Prep')); rename value=prep; drop qsn; run; data temp2; set have (where=(qsn='Strength')); strength=input(value,best12.); drop qsn value; run; data have2; merge temp1 temp2; by id; run; /* summarise data */ data want; set have2; by id; if first.id then call missing(zov,zov_strength,pan,pan_strength,dol,dol_strength); retain zov_strength pan_strength dol_strength; zov+prep='Zov'; if prep='Zov' and strength>zov_strength then zov_strength=strength; pan+prep='Pan'; if prep='Pan' and strength>pan_strength then pan_strength=strength; dol+prep='Dol'; if prep='Dol' and strength>dol_strength then dol_strength=strength; if last.id then output; drop prep strength; run;
... View more