BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rachelcakes
Calcite | Level 5

Hi all,

I've spent a ton of time researching and I can't find a solution to my problem. I have two databases: 1) Survey collected at baseline and 2) Medical data collected at baseline and f/u with data  in multiple rows per ID for different years the data was collected. I tried merging the two datasets by ID, but then the baseline survey doubled because it added the f/u data to the same lines. Any tips?

- Rachel

What I have

Database#1 Survey data (only collected at baseline)

ID     VAR1     VAR2

1          1          2

2          3          2

3          3          1

Database#2 Medical record data (some ID's have both baseline and follow-up data for BMI, but on different rows)

ID      Baseline      Followup      BMI

1        1                 0                 23

1        0                 1                 24

2        0                 1                 20

2        1                 0                 19

3        1                 0                 30

I want my merged database to look like this:

ID     VAR1     VAR2     BMI_baseline  BMI_fu     BMI_change

1          1          2          23                   24            +1

2          3          2          19                   20             -1

3          3          1          30                   .                .

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

If your data are already sorted by ID:

data want (drop=baseline followup);

  merge database1

        database2 (keep=id baseline bmi rename=(BMI=BMI_Baseline)

                   where=(baseline eq 1))

        database2 (keep=id followup bmi rename=(BMI=BMI_FU)

                   where=(followup eq 1))

        ;

  by id;

  BMI_Change=BMI_FU-BMI_Baseline;

run;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

If your data are already sorted by ID:

data want (drop=baseline followup);

  merge database1

        database2 (keep=id baseline bmi rename=(BMI=BMI_Baseline)

                   where=(baseline eq 1))

        database2 (keep=id followup bmi rename=(BMI=BMI_FU)

                   where=(followup eq 1))

        ;

  by id;

  BMI_Change=BMI_FU-BMI_Baseline;

run;

rachelcakes
Calcite | Level 5

Arthur, you just made my day. Thank you so very much!! Smiley Happy:smileylaugh:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 2 replies
  • 704 views
  • 0 likes
  • 2 in conversation