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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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