Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas



Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2009, 11:54 AM
Data _null_;
Guest
 
Posts: n/a
Default Re: Urgent - Please help with the code

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.

>

Reply With Quote
Alt Today
Advertising
Google Adsense
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Popular Tags in the Forum
code, urgent

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


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



Language 1 | C | C++ | Php | Python | Lisp | Perl | Ruby | Java | Pascal | Basic | Language 2 | Databases | Oracle | Mysql | Access | Drupal
All times are GMT. The time now is 04:04 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.