BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi,

I have two datasets with identical variables (Dataset2 is an updated version of Dataset1). Each dataset is unique at the person level and contains ID and about 20 categorical variables. Only a subset of those in Dataset1 are in Dataset2--that is, if any person in Dataset1's information had changed, it would be reflected in Dataset2, but if their information stayed the same, they would not have a record in Dataset2:

Dataset1:

ID     categ_var1     categ_var2...etc

1              a                  d

2              a                  g

3              b                  d

4              c                  e

5              b                  f

Dataset2:

ID     categ_var1     categ_var2...etc

2             a                    b

5             c                    f

What I want is to combine the two datasets such that I have one record for each person, but if they have a record in Dataset2, SAS keeps that record instead of the one from Dataset1:

ID     categ_var1     categ_var2...etc

1              a                  d

2              a                  b

3              b                  d

4              c                  e

5              c                  f

Any help is much appreciated.

1 REPLY 1
ballardw
Super User

I think you may want something like:

data want;

     update dataset1 dataset2;

     by id;  /* each of the source datasets should be sorted by id if they aren't already*/

run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 640 views
  • 0 likes
  • 2 in conversation