BookmarkSubscribeRSS Feed
mmh
Obsidian | Level 7 mmh
Obsidian | Level 7

Hello,
I want to merge CRSP trading days with Compustat event dates.
As you are aware, CRSP daily data file does not contain information for days which are weekends and holidays.
Therefore, event though there might be an event date in Compustat which falls on a holiday, the relevant date in CRSP does not contain any information. So, data is lost when I am trying to merge them.
I have the following files:

data crsp_daily;
input Company_ID $4. Trading_Date;
informat Trading_Date date9.;
format Trading_Date date9.;
cards;
1001 01jan2021
1001 04jan2021
1001 05jan2021
1001 06jan2021
1001 07jan2021
1001 08jan2021
1001 11jan2021
1001 12jan2021
1001 13jan2021
1001 14jan2021
1001 15jan2021
1002 01jan2021
1002 04jan2021
1002 05jan2021
1002 06jan2021
1002 07jan2021
1002 08jan2021
1002 11jan2021
1002 12jan2021
1002 13jan2021
1002 14jan2021
1002 15jan2021
1003 01jan2021
1003 04jan2021
1003 05jan2021
1003 06jan2021
1003 07jan2021
1003 08jan2021
1003 15jan2021
;
run;


data Compustat_date;
input Company_ID $4. Event_date;
informat Event_date date9.;
format Event_date date9.;
cards;
1001 05jan2021
1002 09jan2021
1003 09jan2021
;
run;

I want merge the dates on the following conditions:
1. If an Event_date in Compustat_date file is not present in CRSP_daily file, I want to shift the date in the merged file in the next earliest available Trading_Date. Please see Company_ID 1002 on 09Jan2021 merged on 11Jan2021.

2. However, if the next earliest available trading day is more than 5 Trading_Date later from the Event_date, then I do not want to merge the dates. Rather I want to create a separate file containing that Company.

I am expecting the following output files:
1. First merged file:

Company_IDTrading_DateEvent_Date
10012021-01-01 
10012021-01-04 
10012021-01-052021-01-05
10012021-01-06 
10012021-01-07 
10012021-01-08 
10012021-01-11 
10012021-01-12 
10012021-01-13 
10012021-01-14 
10012021-01-15 
10022021-01-01 
10022021-01-04 
10022021-01-05 
10022021-01-06 
10022021-01-07 
10022021-01-08 
10022021-01-112021-01-11
10022021-01-12 
10022021-01-13 
10022021-01-14 
10022021-01-15 
10032021-01-01 
10032021-01-04 
10032021-01-05 
10032021-01-06 
10032021-01-07 
10032021-01-08 
10032021-01-15 

 

Second output file containing company that is not merged:

Company_IDEvent_Date
10032021-01-09

 

Thank you in advance for your kind support!

2 REPLIES 2
mkeintz
PROC Star

What if you have an event for a company that precedes the first trading date for that company?   Would you still apply the 5-day limit?

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
mmh
Obsidian | Level 7 mmh
Obsidian | Level 7
Thanks a lot for asking!
I don't think that would be the case in my actual dataset.
But if that is the case, I would still want to impose the 5-day limit.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 545 views
  • 0 likes
  • 2 in conversation