|
|||
|
One small problem. Your solution is not correct.
On 11/26/09, Søren Lassen <s.lassen@post.tele.dk> wrote: > A number of solutions have been posted already, but all of them > involve summing 5 numbers in every iteration of the datastep. > That is not really necessary, you can just subtract the number that > is going out of the queue: > > data a; > input Val1; > cards; > 10 > . > 20 > 30 > . > 40 > 50 > 30 > . > . > 10 > 20 > 30 > 40 > . > ; > run; > > data b; > set a; > sum5+val1; > if _n_>5 then do; > set a(keep=val1 rename=(val1=_subtract)); > sum5+-_subtract; > end; > drop _:; > run; > > The program does generate a "Missing values were generated..." > message, because of the unary minus operator in "sum5+-_subtract;" > - if you don't like that, change the line to > > if _subtract ne . then sum5=sum5-_subtract; > > Regards, > Søren > > > > On Tue, 24 Nov 2009 02:53:04 -0800, Zish <zishanpurple@GMAIL.COM> wrote: > > >The data set looks like > > > >Val1 Sum of last 5 (Non Blank) > >10 . > >. 10 > >20 10 > >30 30 > >. 60 > >40 60 > >50 100 > >30 150 > >. 170 > >. 170 > >10 170 > >20 160 > >30 150 > >40 130 > >. 130 > > > >I need to write a code which calculates the second column, which is > >the sum of last five values present in column1. > |
|
|
||||
|
||||
|
|
![]() |
| Popular Tags in the Forum |
| code, urgent |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to make Forth interesting? | DavidM | Newsgroup comp.lang.forth | 73 | 05-08-2009 07:30 AM |
| Re: how to get list of datasets "created" between SAS code? | ajay ohri | Newsgroup comp.soft-sys.sas | 0 | 06-13-2008 05:32 AM |
| Re: how to get list of datasets "created" between SAS code? | Ya Huang | Newsgroup comp.soft-sys.sas | 0 | 06-13-2008 05:27 AM |
| Re: How can one eliminate Error statement in the following code? | Ian Whitlock | Newsgroup comp.soft-sys.sas | 0 | 01-19-2007 09:27 PM |
| Re: Create a dataset with first person on the Code for each year | data _null_; | Newsgroup comp.soft-sys.sas | 0 | 11-16-2006 07:52 PM |