Last active
September 24, 2022 09:22
-
-
Save joosti/0043ed9bbf525a9f3fb1 to your computer and use it in GitHub Desktop.
Downloading multiple datasets from SAS
This file contains hidden or 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
/* | |
fetch: fetches a dataset from WRDS and creates simple indices | |
dependency: this macro uses Clay macro %DO_OVER | |
remLib: remote library directory (e.g. /wrds/crsp/sasdata/a_stock ) | |
locLib: local library name (e.g. work) | |
dset: dataset to download (e.g. dsenames) | |
indices (optional): variable names on dset to create index on after download (e.g. permno) | |
*/ | |
%macro fetch(remLib=, locLib=, dset=, indices=""); | |
/* push macro variables to server */ | |
%syslput remLib = &remLib; | |
%syslput locLib = &locLib; | |
%syslput dset = &dset; | |
rsubmit; | |
/* assign library */ | |
libname get "&remLib"; | |
/* download */ | |
%put downloading &dset in &remLib to &locLib..&dset; | |
proc download data=get.&dset out=&locLib..&dset;run; | |
endrsubmit; | |
/* create indices if needed */ | |
%if &indices ne "" %then %do; | |
%put making indices: &indices; | |
proc sql; | |
%DO_OVER(values=&indices, phrase=create index ? on &locLib..&dset;) ; | |
quit; | |
%end; | |
%mend; |
This file contains hidden or 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
**************************** set this; | |
%let moYear = 2014_Nov; | |
%let topDir =C:\_sas_libfiles\wrds\; | |
****************************; | |
%let wrds = wrds.wharton.upenn.edu 4016;options comamid = TCP remote=WRDS; | |
signon username=_prompt_; | |
/* create directory structure: moYear/crsp, moYear/comp, moYear/ibes in topDir */ | |
%put creating directory: &topDir.&moYear; | |
systask command "mkdir &topDir.&moYear" ; | |
%put creating directory: &topDir.&moYear.\comp; | |
systask command "mkdir &topDir.&moYear.\comp" ; | |
%put creating directory: &topDir.&moYear.\crsp; | |
systask command "mkdir &topDir.&moYear.\crsp" ; | |
%put creating directory: &topDir.&moYear.\ibes; | |
systask command "mkdir &topDir.&moYear.\ibes" ; | |
/* library assignments */ | |
libname newComp "&topDir.&moYear.\comp"; | |
libname newCrsp "&topDir.&moYear.\crsp"; | |
libname newIbes "&topDir.&moYear.\ibes"; | |
/* Compustat | |
--------- */ | |
/* Funda, Fundq */ | |
/* download and simple indices*/ | |
%fetch(remLib=/wrds/comp/sasdata/naa, locLib=newComp, dset=funda, indices=cusip fyear tic); | |
%fetch(remLib=/wrds/comp/sasdata/naa, locLib=newComp, dset=fundq, indices=cusip fyear tic); | |
/* add compound indices on gvkey, datadate*/ | |
proc sql; create index gvkey_datadate on newComp.funda(gvkey, datadate);quit; | |
proc sql; create index gvkey_datadate on newComp.fundq(gvkey, datadate);quit; | |
/* CRSP | |
---- */ | |
/* dsenames */ | |
%fetch(remLib=/wrds/crsp/sasdata/a_stock, locLib=newCrsp, dset=dsenames, indices=permno cusip); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment