Dear SAS Community, I would like to calculate the mean of a variable for each year and month in a specific time period. I programed a do loop over a proc summary step to do so. The problem is that I only get back the results for the last iteration of the loop. But I need the results of all the iteration. I suppose that the loop overwrites the results of former iterations. Do you know a possibility to store the results of each iteration? Or would you suggest a data step with an output statement? The dataset includes some numeric variables that represent the date as well as a duration variable. For example: ID eyearmax emonthmax eyear eyear duration 1 2007 6 2007 3 10 1 2007 6 2007 1 15 1 2007 6 2007 6 28 2 2008 5 2007 5 10 3 2007 11 2006 7 11 3 2007 11 2007 11 19 4 2008 1 2008 1 7 %macro test (eyear=, emonth=,); %DO eyear = 2007 %TO 2009; %DO emonth = 1 %TO 12; proc summary data=work.want (where=(eyearmax<=&eyear. and emonthmax<=&emonth.)) nway sum; class id; output out=work.duration sum(duration)=; run; proc summary data=work.duration mean; output out=work.meanduration (drop=_freq_ _type_) mean (duration)=; run; %end; %end; %mend test; %test; Thank you very much for your help! Best regards, Sabeth
... View more