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
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.);
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.);
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.
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.