Date: Fri, 24 Dec 1999 13:29:51 +0100
Reply-To: Frank Poppe <poppe-f@pzh.nl>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Frank Poppe <Frank.Poppe@KNOWARE.NL>
Organization: Knoware
Subject: Re: Subselect of sas dataset
This sounds like a kind of Christmas puzzle ;-).
The number of possible combinations of 78 different (?) records from 250
records is rather large.
To weed out the improbable combinations as fast as possible I'd sort the
dataset on amount (descending), and then set up nested loops to select all
combinations, leaving a level as soon as 250.000 has been exceeded.
(If the dot in 250.000 is a decimal dot precision becomes an issue when the
amount has to be exactly 250.000, but I have a feeling this is a European
notation).
The DATA step (after the sort has been done) would then look more or less
like:
total0 = 0 ;
DO i1 = 1 to 250 WHILE total < 250000 ;
SET data ( POINT = i1 ) ;
total1 = total0 + amount ;
DO i2 = i1 to 250 WHILE total < 250000 ;
SET data ( POINT = i2 ) ;
total2 = total1 + amount ;
....
DO i78 = i77 TO 250
SET data POINT = i78 ;
total78 = total77 + amount ;
IF total78 = 250000 then put _ALL_ ;
and a series of END's.
A macro to produce that would be
%MACRO combo ( ncomb , nobs , data ) ;
DATA combo ;
total0 = 0 ; i0 = 1 ;
%DO i = 1 %TO &ncomb ;
%let imin = %eval ( &i - 1 ) ;
DO i&i = i&imin TO &nobs ;
SET &data POINT = i&i ;
total&i = total&imin + amount ;
%END ;
IF total&ncomb = 250000 THEN OUTPUT ;
%DO i = 1 %TO &ncomb ;
END;
%END ;
RUN ;
%MEND ;
A call of %combo ( 78 , 250 , yourlib.yourdata ) would work, but take a
(very...) long time.
Frank Poppe
Dirk Cosijn <dirk.cosijn@village.uunet.be> wrote in message
news:83u0mc$3n1$1@newnews1.news.nl.uu.net...
> Hello everyone,
>
> I have a sas dataset with 250 obs. Each obs has two variables (key and
> amount).
> There's 1 combination of 78 obs with a total amount of 250.000
> I lost a second dataset which i have used to make the combination of 78
obs.
>
> Now I'm trying to find the combination of 78 obs (total amount=250.000)
> again without my second dataset.
>
> Any idea how i can make different combinations of 78 obs until i find a
> total amount of 250.000
>
> Many Thanks
>
>