Date: Mon, 19 Oct 2009 11:31:23 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: running total
you can try:
data x;
set a;
retain s 0;
if var3=0 then s = sum(s,var1);
else s=0;
run;
Gerhard
On Mon, 19 Oct 2009 07:38:30 -0700, Thx for your HELP
<jjongwooc@GMAIL.COM> wrote:
>Hi,
>
>data a;
>infile cards dlm=",";
>input var1 var2 var3;
>cards;
>1.74,1,0
>10.95,2,0
>4.85,3,0
>3.15,4,0
>.,1,1
>0.87,1,0
>6.28,2,0
>4.85,3,0
>3.15,4,0
>.,1,1
>0.43,1,0
>3.94,2,0
>3.04,3,0
>2.02,4,0
>;
>run;
>
>
>using the above dataset, I would like to calculate the running totals
>of "var1" until you reach the missing value in var1 (when var3 = 1)
>and restart the running totals again.
>Ultimately, the new data would look something like below.
>
>data newdata;
>infile cards dlm=",";
>input var1 var2 var3 total;
>cards;
>1.74,1,0,1.74
>10.95,2,0,12.69
>4.85,3,0,17.54
>3.15,4,0,20.69
>.,1,1
>0.87,1,0,0.87
>6.28,2,0,7.15
>4.85,3,0,12
>3.15,4,0,15.15
>.,1,1
>0.43,1,0,0.43
>3.94,2,0,4.37
>3.04,3,0,7.41
>2.02,4,0,9.43
>;
>run;
>
>
>any help will be greatly appreciated.
>
>Thank you very much
|