BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I am trying to add AGE and BMI data in data1 to the data2 based on #ID. Since the two data sets have different No. of observations, I have trouble to add them. Could some one help me with this?

Thanks

DATA1
#ID AGE BMI
5001 41 22.7
5001 41 22.7
5001 41 22.7
5003 50 24.5
5003 50 24.5
5003 50 24.5
5003 50 24.5
.
.
.
.
.
.


DATA2
#ID TIME AMT
5001 0 0
50010 0
5001 0 0
5001 0 0
5001 0 0
5001 0.01 6800
5001 0.01 6800
5001 0.01 6800
5001 0.083 0
5003 0 .
5003 0.01 8900
5003 0.083 .
5003 0.167 .
5003 0.25 .
5003 0.333 .
5003 0.5 .
5003 0.75 .
.
.
.
.
.
.
..
.
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You should explain what the OUTPUT side (expected) is to appear. The MERGE process can use a BY statement, listing the merge variable values.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
> You should explain what the OUTPUT side (expected) is
> to appear. The MERGE process can use a BY statement,
> listing the merge variable values.
>
> Scott Barry
> SBBWorks, Inc.

sorry about that.

The output should be like following:
#ID TIME AMT AGE BMI
5001 0 0 41 22.7
5001 0 0 41 22.7
5001 0 0 41 22.7
5001 0 0 41 22.7
5001 0 0 41 22.7
5001 0.01 6800 41 22.7
5001 0.01 6800 41 22.7
5001 0.01 6800 41 22.7
5001 0.083 0 41 22.7
5003 0 . 50 24.5
5003 0.01 8900 50 24.5
5003 0.083 . 50 24.5
5003 0.167 . 50 24.5
5003 0.25 . 50 24.5
5003 0.333 . 50 24.5
5003 0.5 . 50 24.5
5003 0.75 . 50 24.5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
As was suggested, with your two files loaded as SAS datasets, sort and use a DATA step MERGE with a BY statement.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
sounds like : take one case for each ID of AGE and BMI (hopefully there would only be one unique pair of values for one ID ) apply in 1:n merge with data2 by ID
proc sql _method ;
create table joined as
select a.*, b.age, b.bmi
from data2 as a
join (select distinct id, age, bmi from data1 ) as b
on a.id=b.id
;
quit ;
proc print ;
run ;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 837 views
  • 0 likes
  • 3 in conversation