BookmarkSubscribeRSS Feed
attjooo
Calcite | Level 5

I have three data sets ONE, TWO and THREE.

They have the same variables: ID, VAR1, VAR2, VAR3 and VAR4.

Each ID can have multiple records. Each ID can be member of more than one of the data sets: 1, 2 or all three. If so, the ID:s records are the same in all the data sets where the ID occurs.

I want to have each ID:s all records in one data set: RESULT.

If I first sort ONE, TWO and THREE by ID, will the following code produce what I want, or can it be done even simpler?

DATA RESULT;

SET ONE TWO THREE;

BY ID;
RUN;

9 REPLIES 9
LinusH
Tourmaline | Level 20

Or do the sort after the data - set step.

And you wish to keep all records, including duplicates?

Data never sleeps
attjooo
Calcite | Level 5

I want duplicates only if the duplicates were there from the start.

Your question indicates that my code example create duplicates.

LinusH
Tourmaline | Level 20

Not creates, preserves rather...

Data never sleeps
Kurt_Bremser
Super User

The question is, should dataset result have x records where x is the sum of all records of one,two,three, regardless of the contents, or should records be eliminated if two identical records are found in different datasets?

attjooo
Calcite | Level 5

I give an example:

ID = 1 have a total of 2 reccords in data set ONE.

ID = 1 does not occur in data set TWO..

ID = 1 occurs also in data set THREE with the same 2 records as in data set ONE.

In data set RESULT,  ID = 1 should have the same 2 records as in data set ONE and THREE, and NOT those 2 records twice.

LinusH
Tourmaline | Level 20

Then you need to add a PROC SORT NODUPRECS after the data - set step.

Data never sleeps
Reeza
Super User

What about using an update statement instead?

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
  • 9 replies
  • 1081 views
  • 0 likes
  • 4 in conversation