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
| /* push number of unique firms into macro variable numfirms */ | |
| proc sql; | |
| select count(*) into :numfirms from (select distinct gvkey from work.sample); | |
| quit; | |
| %put Number of distinct firms in sample: &numfirms; |
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
| /* | |
| macro that computes the Herfindahl index for each industry-year | |
| indVar can be SIC or NAICS | |
| dsin needs to have gvkey, fyear, SICH or NAICSH | |
| sample use: %computeIndSales(dsin=work.start, dsout=work.indsales, indVar=NAICS); | |
| */ | |
| %macro computeIndSales(dsin=, dsout=, indVar=SIC); | |
| /* code for SIC */ |
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
| /* begin and end date to sample random game release dates */ | |
| %let startDate = 01/01/2006; | |
| %let endDate = 12/31/2011; | |
| /* convert to integer (internal representation of dates) */ | |
| %let startDateInt = %sysfunc(inputn(&startDate,MMDDYY10.)); | |
| %let endDateInt = %sysfunc(inputn(&endDate,MMDDYY10.)); | |
| /* range is 2190 days for 2006-2011 */ | |
| %let range = %eval(&endDateInt - &startDateInt); |
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
| data sample; | |
| set sample; | |
| if year <= 1997 then do; | |
| preSFAS131 = 1; | |
| /* .. more code .. */ | |
| end; | |
| else do; | |
| preSFAS131 = 0; | |
| /* .. more code .. */ | |
| end; |
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
| %macro connectWrds; | |
| %let wrds = wrds.wharton.upenn.edu 4016; options comamid = TCP remote=WRDS; | |
| signon username=_prompt_; | |
| %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
| /* variable assignments */ | |
| %let tableDir = C:\myProject\sas_output\; | |
| %let vars = roa roe asset_turn; | |
| /* create descriptive statistics */ | |
| proc means data=myDataset NOPRINT; | |
| output out=table1 mean= median= std= min= max= p25= p75= N=/autoname; | |
| var &vars; | |
| run; |
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
| /* | |
| libInfo - info on datasets in library | |
| libInfo (lib=, dset=, attr=, eng=, vars=) | |
| lib: library, default is work | |
| dset: dataset, default is _all_ | |
| attr: output dataset with attributes, default is work.attr | |
| eng: output dataset with engine, default is work.eng | |
| vars: output dataset with variables, default is work.vars |
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
| proc sql; | |
| create table work.dsOut as | |
| /* select a.* means select all variables in a | |
| select a.sale / b.sale - 1 means divide sales of year a by sales of year b minus 1 | |
| as sales_growth renames this to sales growth | |
| b.fyear is included for debugging (to make sure prev_fyear is indeed previous year) | |
| */ | |
| select a.*, a.sale / b.sale - 1 as sales_growth, b.fyear as prev_fyear | |
| from | |
| work.dsIn a, work.dsIn b |
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
| proc sql; | |
| create table work.dsOut as | |
| /* a.* means all records from work.dsIn | |
| b.effdate means select effdate from misc.sdc | |
| / | |
| select a.*, b.effdate | |
| from work.dsIn a | |
| /* perform a left join */ | |
| left join misc.sdc b | |
| /* require that gvkey is the same */ |
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
| /* count observations per firm: group by on one variable */ | |
| proc sql; | |
| create table work.dsOut as select gvkey, count(*) as numYears from work.dsIn group by gvkey; | |
| quit; |