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 ;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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