Date: Tue, 23 Apr 1996 18:26:29 PDT
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
Subject: Re: Combining Records To $3.00
Regarding finding all combinations totaling some amount:
INPUT @1 ACCOUNT $10. @11 ASDOLLAR 10.2;
PROC SORT DATA=SKINNY OUT=SORTED;
PROC TRANSPOSE DATA=SKINNY OUT=PENNY PREFIX=PENNY;
PROC TRANSPOSE DATA=SKINNY OUT=SERIAL PREFIX=SERIAL;
* WIDE has variables ACCOUNT, PENNY1-PENNYn, SERIAL1-SERIALn;
* Find the value of n--it must be less than 100;
PROC MEANS NWAY NOPRINT DATA=SASHELP.VCOLUMN;
WHERE LIBNAME EQ 'WORK' AND MEMTYPE EQ 'VIEW' AND MEMNAME EQ 'WIDE'
AND NAME EQ: 'SERIAL';
LENGTH BIT $&varcount;
ARRAY _PENNY PENNY1-PENNY&varcount;
ARRAY _SERIAL SERIAL1-SERIAL&varcount;
DO VERYBAD=0 TO 2**&varcount-1;
DO MAYUSE=1 TO &varcount;
IF SUBSTR(BIT,MAYUSE,1) EQ '1'
IF TOTAL EQ &goal
* Output routine left to the student;
I cannot promise it is right--I'd test it a few time putting out the limits of
Tim Berryhill - Contract Programmer and General Wizard
TWB2@PGE.COM or http://www.lookup.com/Homepages/92062/home.html
Frequently at Pacific Gas & Electric Co., San Francisco
The correlation coefficient between their views and
my postings is slightly less than 0
----------------------[Reply - Original Message]----------------------
Sent by:Tony Gutschmidt <0002759027@MCIMAIL.COM>
I can multiply the numbers by 100 to avoid round-off errors, and I
can go with no negative numbers but the assumption that I would never
want a four+ number combination is incorrect. The example I gave was
fairly simple, but there could be more than three numbers that add up
to the total I'm looking for. I could set an arbitrary limit like 8
which would probably cover a lot of cases, but ideally the program could
handle any number. Again, I'd typically be looking at 30 records or less.
>I'll assume that all values are positive,
>and that you never want a four (or five or six or ...) number combination,
>and that you've premultiplied each number by 100,
>to eliminate the fractions, and, thus, the possibility of "round-off".
Date: Thu Apr 18, 1996 8:12 pm CST
Source-Date: Thu, 18 Apr 1996 18:18:18 PDT
From: Melvin Klassen
EMS: INTERNET / MCI ID: 376-5414
TO: * Tony Gutschmidt / MCI ID: 275-9027
Subject: Re: SAS Help
Tony Gutschmidt <0002759027@MCIMAIL.COM> writes:
>Take a set of numbers and come up with every possible combination
>that will sum up to a given total. For instance, let's say I have
>the following numbers and need to determine which ones add up to 3.00.
Summing "fractional" numbers is fraught with the danger of
"round-off" problems, i.e., the computer's sum of '0.1+0.9'
will be *LESS* than '1.0'.
> # value
> 1 1.00
> 2 1.00
> 3 1.00
> 4 1.25
> 5 1.25
> 6 1.50
> 7 1.75
> 8 2.00
> 9 2.50
>This will be part of a tool I need to research billing records.
>The number of records will be variable, but typically under 30.