BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
evvvvvvvvv
Calcite | Level 5

Hi everyone. 

I have two dataset that need to be merged: The first dataset contains around 39k observations, which are acquistion activities taken by U.S firms. The dataset contains the firms' unique ID (called PERMNO), and the date on which the acquisitions were completed. I want to merge this dataset with the second dataset, which contains PERMNO and each firm's quarterly accounting data (eg total asset) over a period of time.

 

I format the date of both dataset as yyq. (ie. year and quarter), then sort them by PERMNO and date. I then merge by PERMNO and date using proc sql, the code is as follows:

 

proc sql;
create table want as
select dataset1.*,dataset2.*
from dataset1 left join dataset2
on dataset1.PERMNO=dataset2.LPERMNO and dataset1.date=dataset2.datadate;
quit;

 

 

However the merged table has a significant amount of observations missing, which should not be the case according to the two original datasets.  Have I missed something?

 

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

 

It's impossible to reply without sample data, but one thing stands out:

 

 > I format the date of both dataset as yyq. (ie. year and quarter), then sort them

 

formatting has no effect on the sort or the merge, it only affects how the value is displayed.

 

If you want to merge by quarter you need to make this known. Either create a new variable, or change the SQL:

 

on  dataset1.PERMNO=dataset2.LPERMNO

and put(dataset1.DATE,yyq.)=put(dataset2.DATADATE,yyq.);

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

 

It's impossible to reply without sample data, but one thing stands out:

 

 > I format the date of both dataset as yyq. (ie. year and quarter), then sort them

 

formatting has no effect on the sort or the merge, it only affects how the value is displayed.

 

If you want to merge by quarter you need to make this known. Either create a new variable, or change the SQL:

 

on  dataset1.PERMNO=dataset2.LPERMNO

and put(dataset1.DATE,yyq.)=put(dataset2.DATADATE,yyq.);

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
  • 800 views
  • 1 like
  • 2 in conversation