Date: Thu, 15 Sep 2005 14:58:31 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: lead function
Urvir,
Without getting into why you might want to do it, there are numerous
ways. Retain within a datastep is definitely one, but most of the work
would be maintaining your desired order.
data one;
input cnt pct1 pct2;
recnum=_n_;
cards;
30 12 12
40 10 10
40 5 5
;
run;
proc sort data=one;
by descending recnum;
run;
data two (keep= recnum sumcnt sumpct1 sumpct2
rename=(sumcnt=cnt sumpct1=pct1 sumpct2=pct2));
retain sumcnt sumpct1 sumpct2;
set one;
if _n_ eq 1 then do;
sumcnt=cnt;
sumpct1=pct1;
sumpct2=pct2;
end;
else do;
sumcnt=sumcnt+cnt;
sumpct1=sumpct1+pct1;
sumpct2=sumpct2+pct2;
end;
run;
proc sort data=two out=one (drop=recnum);
by recnum;
run;
Art
----------
On Thu, 15 Sep 2005 11:38:26 -0700, urbunti <urbunti@YAHOO.COM> wrote:
>I have a dataset
>
>cnt pct1 pct2
>30 12 12
>40 10 10
>40 5 5
>
>i want
>cnt pct1 pct2
>110 27 27
>80 15 15
>40 5 5
|