Encoding: 112 TEXT
X-Mailer: Microsoft Mail V3.0
Newsgroups: bit.listserv.sas-l
Date:         Tue, 5 Jan 1993 14:00:00 EST
Reply-To:     rjf2@PHPDLS1.EM.CDC.GOV
From:         rjf2@PHPDLS1.EM.CDC.GOV
Subject:      Match Merge Problem
Comments: To: SAS-L@uga.cc.uga.edu

content      : Response
summary      : data manipulation: 2 solutions to match merge problem
rlse/platform: V6.07 / MVS
Ron Fehd     :                SMTP:BitNet:    <rjf2@phpdls1.em.cdc.gov>
              Centers for Disease Control
              1600 Clifton Rd  MS:G25         FAX  : 404/639-1778
              Atlanta, GA 30333  USA          phone: 404/639-1707
????????????????????????????????????????????????????????????????????
Reply-To:     Frank Dane <FDANE@uga.cc.uga.edu>
Subject:      Match Merge Problem
Platform:  Windows 6.08 Developer's Version
Problem:   MERGE doesn't behave

I've got a data file on coronary arrests that looks like:

pt#  varA1 varB1 ncode ...
12    90    100   1
12    85    50    2
13    70    80    1

in which each subsequent appearance of the same pt# represents a
second (ncode = 2) or third arrest episode on the same patient.
I tried extracting all cases for ncode = 1 into one file, call it
code1, and then all cases with ncode = 2 into a second file,
code2.  When I tried a match merge in order to do some repeated
measures analyses, what I wanted was:

pt#  varA1 varB1 varA2 varB2
12    90    100   85    100
13    70    80     .     .

but what I got was:

pt#  varA1 varB1 varA2 varB2
12    90    100    .     .
12     .      .   85    50
13    70    80     .     .

Within files code1 and code2, pt# is a unique identifier and is
the only variable name common to both files.  Both code1 and
code2 have been sorted by pt#, although code2 contains only about
a third as many cases as code1.

The code was:

DATA people;
     merge code1 code2;
     by pt#;

Can someone tell me what went wrong. or suggest a better way to
accomplish what I want?

TIA,
Dr. Francis C. Dane, Associate Professor and Chair
Department of Psychology, Mercer University
Macon, GA  31207-0001  USA
Bitnet: FDANE@UGA   Internet: FDANE@UGA.CC.UGA.EDU
Tel: (912) 752-2972
Fax: (912) 752-2108
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
well, looks like you may have a problem with your version.

I assume that you tried the following code to build your Code1, Code2 data:

DATA CODE1
     CODE2(rename = (VarA1=VarA2 VarB1=VarB2)
     ...
     CODEN(rename = (VarA1=VarAn VarB1=VarBn) ;
  set <something>;
  select(NCode);
    when (1) output Code1;
    when (2) output Code2;
    ...
    when (N) output Coden;
    otherwise;                                        end;
  drop NCode;

DATA PEOPLE;
  merge CODE1
        CODE2
        ...
        CODEN;
  by pt#;

now here's another data build solution with arrays and retain:

DATA PEOPLE;
  set <something>;
  by Pt# NCode;
  retain VarA1 VarA2 ... VarAn
         VarB1 VarB2 ... VarBn 0;
  select(NCode);
    when (1);
    when (2) do; VarA2 = VarA1;
                 VarB2 = VarB1;                 end;
    when (3) do; VarA3 = VarA1;
                 VarB3 = VarB1;                 end;
    ...
    when (N) do; VarAN = VarA1;
                 VarBN = VarB1;                 end;
    otherwise;                                  end;
    if last.NCode then output;

and of course there's proc TRANSPOSE;

happy crunching**********************************************************;
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU