Date: Thu, 8 May 2008 08:52:35 -0400
Reply-To: Tom Hide <tom.hide@DEHIWORLD.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tom Hide <tom.hide@DEHIWORLD.COM>
Subject: Re: How to retrieve observations whose sum <= a value
On Wed, 7 May 2008 23:41:18 -0700, abshakes <ab_shakes@YAHOO.COM.SG> wrote:
>Hi All,
> I have a sorted dataset, from which I want to retrieve only those rows
whose sum <= a value.
> In other words I am trying to retrieve only the top n rows whose sum
<=x.
> I will really appreciate any ideas on this....
> Many Thanks !!
> Abhi
>
>
>"I am not arrogant ... only better thaaaan yyyyou !!"
>
>---------------------------------
>Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
it now.
Hiya
Assume your TEST data is as follows:
Var Desc
12 Hhxhxhh
13 aHADHKHasKF
43 VSHGJHJHGJ
data results;
retain cnt 0 x 28;
set TEST;
cnt=sum(cnt,var);
if cnt gt x then stop;
run;
Results
CNT X Var Desc
12 28 12 Hhxhxhh
25 28 13 aHADHKHasKF
CNT will give you a running total for var.
X is your value
I am not sure if this is what you want, if not please supply some more
detailed information, together with sample data and expected results.
Tom