BookmarkSubscribeRSS Feed
pacman94
Calcite | Level 5

Hello I have 3 datasets and as you can see, Ids from one table compared to another is not always the case. 

 

I need to merge all 3 datasets by id and if variable(s) don't exist then they need to be blank:

 

Dataset1:

IDagegender
1215F
2318F
3316M
4214F

 

Dataset2:

IDSchoolYearCityState
12FreshmenBrooklineMA
42FreshmenBrooklineMA
46SeniorFraminghamMA
48SeniorQuincyMA

 

Dataset3

IDMathGradeEnglishGrade
237565
468199
489565

 

Want

IDagegenderSchoolYearCityStateMathGradeEnglishGrade
1215FFreshmenBrooklineMA  
2317F   7565
3316M     
4214FFreshmenBrooklineMA  
46  SeniorFraminghamMA8199
48  SeniorQuincyMA9565

 

What i have done so far is the following:

proc sql; 

create table uniqueID as 

select distinct ID from dataset1 union

select distinct ID from dataset2 union

select distinct ID from dataset3 ;

quit;

 

then

proc sql;

select a.*, b.*, c.*

from uniqueID a 

left join dataset1 b on a.ID = b.ID

left join dataset2 b on a.ID = b.ID

left join dataset3 c on a.ID = c.ID;

quit;

not geting what i look for. 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

not geting what i look for.

are there errors in the log?

 

Please provide data in a usable form, following these instructions. Screen captures are not usable.

--
Paige Miller
Astounding
PROC Star

It looks like your data sets:

 

  1. Are already in order by ID
  2. Have no duplicates (more than one record with same ID)

 

If that's the case, the solution is simple:

 

data want;
   merge dataset1 dataset2 dataset3;
   by id;
run;

If you might have multiple records for the same ID, we need to know more about what the final result should look like.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 620 views
  • 1 like
  • 3 in conversation