BookmarkSubscribeRSS Feed
fongdo
Obsidian | Level 7

I would like to merge the data from Compustat (Quarterly) and CRSP (monthly) by FimID. I have created COMP_T and CRSP_T by merging year and month. Now I would like to get a new dataset where for each FirmID, every month of COMP_T is merged with next three months of CRSP_T. For example, 197912 of COMP_T is merged with the data of 198001, 198002, and 198003 from CRSP_T. Please see a small sample below:      Thank you very much for your help.     

HAVE

Compustat

FrimID           COMP_DATE      COMP_T              Asset    

1                     31/12/1979         197912                  10          

1                     31/03/1980         198003                  20

2                     30/09/1980         198009                  30

 

CRSP

FrimID             CRSP_DATE      CRSP_T               Return

1                      31/12/1979         197912                  0.04

1                      31/01/1980         198001                  0.02

1                      29/02/1980         198002                  0.03

1                      31/03/1980         198003                  0.04

1                      30/04/1980         198004                  0.10       

1                      31/05/1980         198005                  0.09

1                      30/06/1980         198006                  0.07

2                      30/09/1980         198009                  0.05

2                      31/10/1980         198010                  0.06

2                      30/11/1980         198011                   0.09

2                      31/12/1980         198012                  0.14

 

WANT

FrimID             COMP_T              CRSP_T                 Asset     Return

1                       197912                 198001                  10           0.02

1                       197912                 198002                  10           0.03

1                       197912                 198003                  10           0.04

1                       198003                 198004                  20           0.10       

1                       198003                 198005                  20           0.09

1                       198003                 198006                  20           0.07

2                       198009                 198010                  30           0.06

2                       198009                 198011                  30           0.09

2                       198009                 198012                  30           0.14

2 REPLIES 2
Patrick
Opal | Level 21

@fongdo 

Please don't post the same question multiple times. 

Haven't you already got an answer here? https://communities.sas.com/t5/SAS-Programming/How-to-merge-the-data-from-Compustat-Quarterly-and-CR... 

 

LinusH
Tourmaline | Level 20
Also, it seems that you get somewhat hang if your data, so it could be expected that you could show some effort on a query.
If you have no idea, start at the school bench (like the free online SAS Programming training).
Data never sleeps

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1138 views
  • 0 likes
  • 3 in conversation