SAS (Base SAS)+
data lab;
input usubjid hgb_v1 hgb_v2 hgb_v3;
datalines;
1001 12.5 13.1 12.8
1002 13.0 14.0 13.5
1003 11.2 11.8 12.0
;
run;
data lab02;
set lab;
maxval = max(of hgb_v1--hgb_v3);
run;- In SAS, row-wise aggregation across columns uses functions with the
ofkeyword followed by a variable list. maxval = max(of hgb_v1--hgb_v3);computes the maximum of the three columns on each row.- The double-dash (
--) expands to every variable betweenhgb_v1andhgb_v3in column order — a concise list when the columns sit next to each other. - If any column is missing, SAS silently skips it in the
max()call; a row with all three missing returns missing. - We can swap
maxformin,mean,sum, ornto compute any of the common row-wise summaries the same way. - We run and check the
maxvalcolumn matches the largest of the three input columns on each row.