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 1998, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 8 Mar 1998 13:19:17 GMT
Reply-To:   Andreas Grueninger <grueni@STUTTGART.NETSURF.DE>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Andreas Grueninger <grueni@STUTTGART.NETSURF.DE>
Organization:   LF.net GmbH, Internet Services, Stuttgart, Germany
Subject:   Re: (no subject given)

Try this one:

DATA test (DROP=c); INPUT A $ B $ Distance; IF (a > b) THEN DO; c = a; a = b; b = c; END; CARDS; Person1 Person2 23 Person2 Person3 40 Person3 Person1 45 Person1 Person4 50 Person4 Person2 60 Person5 Person6 100 Person9 Person5 56 ; RUN; PROC SORT DATA=test; BY a b; RUN;

* --- all possible combinations, but not all distances can be calculated, because no combination of observations exist; PROC SQL; CREATE TABLE temp AS SELECT DISTINCT a FROM test UNION SELECT DISTINCT b FROM test ORDER BY a; QUIT; DATA comb; SET temp NOBS=nobs; IF (_n_ < nobs) THEN DO; DO i=_n_+1 TO nobs; SET temp (RENAME=(a=b)) POINT=i; IF (i < nobs) THEN DO; DO j=i+1 TO nobs; SET temp (RENAME=(a=c)) POINT=j; OUTPUT; END; END; END; END; RUN;

* --- all possible combinations, where distances can be calculated ; DATA comb; LENGTH a b c $8 sumd 8; SET test NOBS=nobs; IF (_n_ < nobs) THEN DO; DO i=_n_+1 TO nobs; SET test (RENAME=(a=a1 b=b1 distance=d1)) POINT=i; IF ((a=a1 AND b^=b1) OR (a^=a1 AND b=b1)) THEN DO; IF (a=a1) THEN c = b1; ELSE c = a1; sumd = distance + d1; OUTPUT; END; END; END; RUN;

On Sat, 7 Mar 1998 15:39:18 -0500, "Charles C. Hinnant" <cchinnan@MAXWELL.SYR.EDU> wrote:

>I have a question regarding generating unique combinations in SAS. > >My data has three variables A , B, and Dist (the distance between the two >variables). > >A B Distance >-- -- --------- >Person1 Person2 23 >Person2 Person3 40 >Person3 Person1 45 >Person1 Person4 50 >Person4 Person2 60 >Person5 person6 100 >Person9 Person5 56 > >Iam trying to find all unique 3 person combinations (groups). > >For instance, in this example the groups would be >(Person1, Person2, Person3) (Person1, Person2, Person4) > >Any ideas would be appreciated...

--------------------------- Andreas Grueninger

PRIVAT: grueni@stuttgart.netsurf.de OFFICIAL: grueninger@lfl.bwl.de ---------------------------


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