Not easy to suggest something without a sample dataset. Just a starter, important note: event numbers must start with leading zeros data test; length kid 8 Event01 Event02 Event03 $ 10 t01a1-t01a10 t02a1-t02a10 t03a1-t03a10 8; drop i; array t01 t01:; array t02 t02:; array t03 t03:; Event01 = 'one'; Event02 = 'two'; Event03 = 'three'; do kid = 1 to 4; do i = 1 to dim(t01); t01 = mod(int(ranuni(0) * 415547409), 2); t02 = mod(int(ranuni(0) * 345345), 2); t03 = mod(int(ranuni(0) * 94532), 2); end; output; end; run; %macro bob; proc sql noprint; select substr(Name, 5) into :VarList separated by ' ' from sashelp.vcolumn where libname = 'WORK' and memname = 'TEST' and Name like 'Event%'; quit; /* VarList contains t01 t02 t03 ... */ data work.NextStep; set work.test; keep kid event: duration_t:; /* the loop creates one sum-function for each event; */ %do i = 1 %to %sysfunc(countw(&VarList)); %let var = %scan(&VarList, &i, %str( )); duration_&var = sum(of &var:); %end; run; %mend; %bob; Now transpose work.NextStep, so that it contains one observation for each kid and event. Afterwards required statistics can be calculated by the usual route (proc means, maybe tabulate).
... View more