LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 25 Mar 2003 13:57:35 -0500
Reply-To:     Jay Weedon <jweedon@EARTHLINK.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jay Weedon <jweedon@EARTHLINK.NET>
Organization: http://extra.newsguy.com
Subject:      Re: determine the combination of 4 number by their sum ?
Content-Type: text/plain; charset=us-ascii

On 25 Mar 03 17:55:29 GMT, yhuang@AMYLIN.COM (Huang, Ya) wrote:

>Hi there, > >I know in general this is not true, but it could be true in some >strict condition. For example, if I have 3 vars a,b,c and each of them >can only takes value of 1 or 3 or 5, then I can determine by their >summation, which one or two or three digits are in the a,b,c (I don't >care the order for now): > >if sum(a,b,c)=1 then there is only one nonmissing var and its value is 1 >if sum(a,b,c)=3 then there is only one nonmissing var and its value is 3 >if sum(a,b,c)=5 then there is only one nonmissing var and its value is 5 >if sum(a,b,c)=4 then there are two nonmissing vars and their values are 1&3 >if sum(a,b,c)=6 then tehre are two nonmissing vars and their values are 1&5 >if sum(a,b,c)=8 then tehre are two nonmissing vars and their values are 3&5 >if sum(a,b,c)=9 then tehre are three nonmissing vars and their values are 1&3&5 > >Now if I have 4 digits: 3,5,7,9: > >3+5=8 >3+7=10 >3+9=12 >5+7=12 >5+9=14 >7+9=16 >3+5+7=15 >3+7+9=19 >5+7+9=21 >3+5+7+9=24 > >As you can see, 12 could be 3+9 or 5+7, therefore 3,5,7,9 is unacceptable. >I am sure I can find a group of 4 digits that can lead to a unique summation >number. I just wonder if there is a better solution to this kind of problem. >Please note, for demonstration purpose, the above example is to add up vars, >my real challenge is to add up a row-wise in sql: > >data xx; >input id visit; >cards; >1 1 >1 3 >1 5 >2 1 >2 . >2 3 >3 . >3 3 >3 5 >; > >proc sql; >select distinct id, > case when sum(visit)=9 then '1&3&5' > when sum(visit)=4 then '1&3' > when sum(visit)=8 then '3&5' > when sum(visit)=6 then '1&5' > else ' ' end as whatsinthegroup >from xx >group by id >; >------- >id whatsinthegroup >------------------- > 1 1&3&5 > 2 1&3 > 3 3&5 > > >Basically, I hope I can do something like >"select visit into : whatisinthegroup separated by ','" >but not to generate a macro var.

I'm not sure where you're going with this, but mathematically I think an obvious strategem is to make sure that the numbers all differ by one or more orders of magnitude. In the simplest instance you could make them all differ by one binary order of magnitude, e.g., use the 4 numbers 1,2,4,8:

1+2=3 1+4=5 1+8=9 2+4=6 2+8=10 4+8=12 1+2+4=7 1+2+8=11 1+4+8=13 2+4+8=14 1+2+4+8=15.

If you think about how these operations are done in binary arithmetic it should be obvious to you that each bit represents the presence or absence of one of the 4 numbers.

JW


Back to: Top of message | Previous page | Main SAS-L page