andp: Linlin's code will work for any number of id's, she just had to generate test data. I understand you already have data; so you don't need the first data step. If you name your variables sum_Month1, sum_Month2, ..., sum_Month10, so that the consecutive number is at the end of the variable name, then you can sometimes use syntax sum_Month1 -- sum_Month10 instead the explicit list of all vars, for instance in defining an array to summarize over a trimester or whatever. data have; informat ID best4. EndDate mmddyy8. Value best8. Days 3.; input ID EndDate Value Days; format EndDate date9.; cards; 1 1/1/00 2 1 1 1/2/00 2 2 1 2/1/00 3 3 1 2/1/00 3 4 1 2/1/00 3 5 2 1/1/00 4 1 2 1/2/00 5 2 2 2/1/00 6 3 2 2/1/00 7 4 2 2/1/00 3 5 3 1/1/00 4 1 3 1/2/00 4 2 3 2/1/00 3 3 3 2/1/00 2 4 3 2/1/00 1 5 ; run; Data have2; format id 8. Days best4.; set have; if mod(Days,30)=1 then Monthval1=Value; else if mod(Days,30)=2 then Monthval2=Value; else if mod(Days,30)=3 then Monthval3=Value; else if mod(Days,30)=4 then Monthval4=Value; else if mod(Days,30)=5 then Monthval5=Value; *more Monthvaln definitions here*; run; proc sort data=have2; by id days; run; %let months=Monthval1 Monthval2 Monthval3 Monthval4 Monthval5; %let sum_months=sum_Monthval1 sum_Monthval2 sum_Monthval3 sum_Monthval4 sum_Monthval5; %let avg_months=avg_Monthval1 avg_Monthval2 avg_Monthval3 avg_Monthval4 avg_Monthval5; proc summary data=have2 ; var Monthval1 -- Monthval5; by id; output out=monthly_stats (drop=_FREQ_ _TYPE_) sum=&sum_months mean=&avg_months; run; * this is the output: s s s s s a a a a a u u u u u v v v v v m m m m m g g g g g _ _ _ _ _ _ _ _ _ _ M M M M M M M M M M o o o o o o o o o o n n n n n n n n n n t t t t t t t t t t h h h h h h h h h h v v v v v v v v v v O a a a a a a a a a a b i l l l l l l l l l l s d 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 3 2 2 3 3 3 2 2 4 5 6 7 3 4 5 6 7 3 3 3 4 4 3 2 1 4 4 3 2 1 *;
... View more