Created
January 22, 2015 17:35
-
-
Save joosti/237e54feba0778d46dbb to your computer and use it in GitHub Desktop.
SAS CCM CRSP Compustat matched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* macro that retrieves permno for Compustat records | |
dsin: dataset to append permno to, required variables: gvkey, and a date variable | |
dsout: dataset to create | |
datevar: name of date variable (e.g. datadate, or event date) | |
sample use: %getPermno(dsin=a_mydata, dsout=b_withpermno, datevar=datadate); | |
*/ | |
%macro getPermno(dsin=, dsout=, datevar=); | |
proc sql; | |
create table &dsout as | |
select a.*, b.lpermno as permno | |
from &dsin a left join crsp.ccmxpf_linktable b | |
on a.gvkey = b.gvkey | |
and b.lpermno ne . | |
and b.linktype in ("LC" "LN" "LU" "LX" "LD" "LS") | |
and b.linkprim IN ("C", "P") | |
and ((a.&datevar >= b.LINKDT) or b.LINKDT = .B) and | |
((a.&datevar <= b.LINKENDDT) or b.LINKENDDT = .E) ; | |
quit; | |
%mend; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment