*********************************************************************************************************; * Last Update: December 2015 *; * *; * This SAS code gets data needed to compute short interest as a fraction of shares outstanding. *; *********************************************************************************************************; libname short 'C:\...\data\SIR data'; *or whatever directory on your personal computer you want to save the SAS datasets; %let wrds = wrds.wharton.upenn.edu 4016; options comamid=TCP; signon wrds username=_prompt_; RSUBMIT; libname sec '/wrds/comp/sasdata/nam/security'; *define directory on WRDS; libname link '/wrds/crsp/sasdata/a_ccm'; proc download data=sec.SEC_SHORTINT out=short.short; proc download data=sec.SEC_MSHARE out=short.shrout; proc download data=link.CCMXPF_LINKTABLE out=short.link; run; ENDRSUBMIT; data short; set short.short; yyyymm = year(datadate)*100+month(datadate); rename datadate = sdate; keep gvkey iid shortint shortintadj yyyymm datadate; run; data shrout; set short.shrout; yyyymm = year(datadate)*100+month(datadate); rename cshom = shrout; rename datadate = date; keep gvkey iid cshom yyyymm datadate; run; proc sort data=short; by gvkey iid yyyymm sdate; *sometimes there are two obs for one firm/yyyymm, one is mid-month and the other is end-month; *keep mid-month obs to be consistent with other obs for which there is only obs per firm/yyyymm; run; proc sort data=short nodupkey; by gvkey iid yyyymm; proc sort data=shrout; by gvkey iid yyyymm; run; data tmp0; merge short (in=m1) shrout (in=m2); by gvkey iid yyyymm; if m1 and m2; if shrout > 0 then sir = shortint/shrout; else sir = .; if sir > 1 then sir = 1; if sir ne .; run; data link; set short.link; if lpermno ne .; if USEDFLAG = 1; if liid = '00X' then delete; if liid = '99X' then delete; run; proc sql; create table tmp1 as select a.*, b.lpermno as permno from tmp0 as a left join link as b on a.gvkey=b.gvkey and a.iid=b.liid and((b.linkdt<=a.date <=b.linkenddt) or (b.linkdt<=a.date and b.linkenddt=.E) or (b.linkdt=.B and a.date <=b.linkenddt)); run;