| Date: | Fri, 12 Apr 1996 10:45:21 -1000 |
| Reply-To: | Chun Huang <CHUN@MANA.MEDSURF.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Chun Huang <CHUN@MANA.MEDSURF.COM> |
| Organization: | Mana Institute |
| Subject: | Re: HELP: "Merging" datasets |
|
Date: Fri, 12 Apr 1996 13:59:03 +-200
Reply-to: Anders Brabaek <teiwa@CENTRUM.DK>
From: Anders Brabaek <teiwa@CENTRUM.DK>
Subject: HELP: "Merging" datasets
To: Multiple recipients of list SAS-L <SAS-L@VM.MARIST.EDU>
I have a small problem "merging" 2 datasets.
One dataset, dataset1,consists of one observation and 2 variables: y1, y2.
The other dataset, dataset2, consists of 7600 observations, each observation has
3 variables: x1, x2, x3.
Now I want to put these two datasets together,
so that I will get 7600 observations,.each consisting of 2+3=5 variables.
Like this:
Dataset1
Obs y1 y2
1 1 0
Dataset2:
Obs x1 x2 x3
1 m 24 33
2 f 45 98
etc
Final
Obs x1 x2 x3 y1 y2
1 m 24 33 1 0
2 f 45 98 1 0
...
7600 m 18 70 1 0
When I run the following code
data Final;
merge dataset1 dataset2;
run;
I only get the observation from dataset1
added to the first observation in dataset2,
but I want to add it to all of the observations in dataset2.
I suppose this should be a fairly easy operation,
but being a novice with SAS I need help.
Please, I need help.
Thanks in advance.
Anders Brabaek
Anders:
How about creating a new ID and then do a match merging. This may not
be an efficient way, but it is easier to understand. Here is an
example:
DATA TEST1;
INPUT Y1 Y2;
ID=999;
CARDS;
1 0
;
RUN;
DATA TEST2;
INPUT X1 X2 X3;
ID=999;
CARDS;
1 10 100
2 20 200
3 30 300
4 40 400
5 50 500
;
RUN;
DATA TEST3;
MERGE TEST1 TEST2;
BY ID;
DROP ID;
RUN;
PROC PRINT;
RUN;
The SAS System 07:42 Friday,
April 12, 1996 34
OBS Y1 Y2 X1 X2 X3
1 1 0 1 10 100
2 1 0 2 20 200
3 1 0 3 30 300
4 1 0 4 40 400
5 1 0 5 50 500
Chun Huang, Ph.D.
Hawaii Osteoporosis Center
Email: chuang@mana.medsurf.com
|