DATA Step, Macro, Functions and more

to merge two datasets

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

to merge two datasets

Hi All,

Please help achieve the below result
I have two tables, Dept1 and details, now i need to create a new table where i need to add the date joining based on the Dept1 column values and the Leave date would be set to a default date of 31Dec9999 for all the columns Emp_Id is missing.

 

Table 1

Details      
Emp_IdNameDeptSalaryDate of JoiningLOPDept1
A001ATech1230013-Jan-1614-Jan-16Tech
A002BAdmin450016-Apr-1517-Apr-15Admin
A003CHosp897016-Apr-1517-Apr-15Hosp
A004DTech87652-Apr-152-Apr-15Tech
A005ETech435679-Apr-159-Apr-15Tech
A006FHosp908728-Apr-1512-May-15Hosp
A087GAdmin987620-Jan-1321-Jun-16Admin
E00057HTech1234517-Mar-1519-Mar-15Tech
E0041IAdmin764517-Mar-1518-Mar-15Admin
E00062JTech8907514-Aug-1414-Aug-14Tech
E00015KTech3456522-May-139-Oct-13Tech
E00076LHosp56720-Jan-1322-Jun-16Hosp
 M MTech8970  Tech
 NNAdmin8765  Admin
 OOHosp43567  Hosp
 PPTech9087  Tech
 QQTech9876  Tech
 RRHosp7645  Hosp
 SSAdmin89075  Admin
 TTTech34565  Tech
 UUAdmin567  Admin
 VVTech7645  Tech
 WWTech89075  Tech
 XXHosp34565  Hosp
 YYHosp89075  Hosp
 ZZHosp34565  Hosp

 

Table 2:

 

Dept 1  
DeptDate of JoiningDate of Leave
Tech13-Jan-1614-Jan-16
Admin16-Apr-1517-Apr-15
Hosp16-Apr-1517-Apr-15
Tech2-Apr-152-Apr-15
Tech9-Apr-159-Apr-15
Hosp28-Apr-1512-May-15
Admin20-Jan-1321-Jun-16
Tech17-Mar-1519-Mar-15
Admin17-Mar-1518-Mar-15
Tech14-Aug-1414-Aug-14
Tech22-May-139-Oct-13
Hosp20-Jan-1322-Jun-16

 

Results:

 

   Result   
Emp_IdNameDeptSalaryDate of JoiningLOPDept1
A001ATech1230013-Jan-1614-Jan-16Tech
A002BAdmin450016-Apr-1517-Apr-15Admin
A003CHosp897016-Apr-1517-Apr-15Hosp
A004DTech87652-Apr-152-Apr-15Tech
A005ETech435679-Apr-159-Apr-15Tech
A006FHosp908728-Apr-1512-May-15Hosp
A087GAdmin987620-Jan-1321-Jun-16Admin
E00057HTech1234517-Mar-1519-Mar-15Tech
E0041IAdmin764517-Mar-1518-Mar-15Admin
E00062JTech8907514-Aug-1414-Aug-14Tech
E00015KTech3456522-May-139-Oct-13Tech
E00076LHosp56720-Jan-1322-Jun-16Hosp
 M MTech897013-Jan-1612-Dec-99Tech
 NNAdmin876516-Apr-1512-Dec-99Admin
 OOHosp4356716-Apr-1512-Dec-99Hosp
 PPTech90872-Apr-1512-Dec-99Tech
 QQTech98769-Apr-1512-Dec-99Tech
 RRHosp764528-Apr-1512-Dec-99Hosp
 SSAdmin8907520-Jan-1312-Dec-99Admin
 TTTech3456517-Mar-1512-Dec-99Tech
 UUAdmin56720-Jan-1312-Dec-99Admin
 VVTech764514-Aug-1412-Dec-99Tech
 YYHosp8907520-Jan-1312-Dec-99Hosp
 ZZHosp3456520-Jan-1312-Dec-99Hosp

Accepted Solutions
Solution
‎07-20-2016 09:19 AM
Super User
Posts: 6,928

Re: to merge two datasets

You do not have a key that sufficently indicates records to be joined, therefore this is not possible.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Regular Contributor
Posts: 240

Re: to merge two datasets

It seems you do not have primary key column in two tables. Whatever way you do the output would need to verified throughly.

 

If you are very sure that records that need to be joined are in same order in both the tables then in that case create new numeric column NEW_COLUMN  in both the table and store record number that may be _N_  or something else whatever you like. This new column would act as suggorate key and now you can join two table with NEW_COLUMN and dept1.

 

 

 

 

 

 

Solution
‎07-20-2016 09:19 AM
Super User
Posts: 6,928

Re: to merge two datasets

You do not have a key that sufficently indicates records to be joined, therefore this is not possible.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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