```Date: Wed, 8 Nov 2006 11:47:41 -0800 Reply-To: Cat Sender: "SAS(r) Discussion" From: Cat Organization: http://groups.google.com Subject: Re: Looping problem Comments: To: sas-l@uga.edu In-Reply-To: <1162952594.273335.188860@h54g2000cwb.googlegroups.com> Content-Type: text/plain; charset="us-ascii" Hi Sum, Try this, but I'm not sure there is no syntax error, I can't test it now: Proc transpose data = a out = atransp (drop = _name_ _label_); Var obs; Id month; Run; Data c; Set atransp; Array val {*} 199001 -- 200605; Array average {*}; /* "running" mean */ Array stdev {*}; /* "running" standard deviation */ Array month \$ {*}; /* Name of the first month used for running estimates */ Last = dim(obsval) - 11; Do I =1 to last; average(i) = round(mean(of val(i)-val(i+11),.1); stdev(i) = round(std(of val(i)-val(i+11)),.1); month(i) = vname(val(i)); End; Drop I last; Run; Proc transpose data = c out = stat (rename = (col1 = RESULT)); Var average: stdev:; Run; Proc transpose data = c out = month (rename = (col1 = TIME)); Var month:; Run; Data all; Set stat month; N = input(substr(_name_, length(_name_,)),best.); TYPE = upcase(compress(_name_,'0123456789')); Run; Proc sort; By n; Run; Data final; Label Time = 'First month from 12-months series'; Merge all (where = (TYPE = 'MONTH') keep = n time) all (where = (TYPE = 'AVERAGE') keep = n result rename = (result = MEAN)) all (where = (TYPE = 'STDEV') keep = n result rename = (result = STD)); by n; run; Catherine. SUM a écrit : > Hi SAS Experts, > I have a problem of calculation in loops. > Suppose i have a data like this: > > > > Month Obs > 199001 40 > 199002 45 > 199003 22 > .. > > > 199012 25 > . > . > . > > > 200605 42 > > Now i have to calculation mean and standard deviation using each 12 > months data. First calculation will be done for 199001 - 199012, > second will be 199002 - 199101, third will be 199003 - 199102, and so > on. How can i proceed using a loop? Please help. > > Sumanta. ```

Back to: Top of message | Previous page | Main SAS-L page