Search code examples
sas

proc sql perform same operation over multiple columns


I have a dataset with 20 columns all starting with the name morb_, which are all 1 or 2, coded as No and Yes. There is an additional column called Pat_TNO which is the patient reference number. Patients have more than one row.

I wish to create a new dataset which summarises whether each patient has had at least one of each type of event. So far the code I have written works perfectly, but is there a way to simplify it using an array?

proc sql;
   select
      Pat_TNO,
      max(morb_1) as morb_1 format yn.,
      max(morb_2) as morb_2 format yn. /* etc etc */
   from morbidity
   group by Pat_TNO;
quit;

COumn names aren't morb_1 and morb_2, rather morb_amputation, morb_mi, morb_tia, etc.


Solution

  • proc summary data=morbidity nway missing;
       class pat_tno;
       output out=max max(morb_:) = ;
       run;