Created
July 1, 2016 17:24
-
-
Save JoostImpink/dc879c1cddf4e655d95f043cb7c44f40 to your computer and use it in GitHub Desktop.
Macro to create dummy variables (non-missing values only)
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
/* Helper macro to make dummy variables | |
Note: it is not robust for missing values | |
*/ | |
%macro createDummyVars(dsin=, var=, newvar=); | |
proc sql noprint; | |
select distinct &var. into :mvals separated by '|' | |
from &dsin.; | |
/* Number of unique values */ | |
%let mdim=&sqlobs; | |
quit; | |
data &dsin.; | |
set &dsin.; | |
/* Loop through #unique values */ | |
%do _i=1 %to &mdim.; | |
/* Grab value */ | |
%let _v = %scan(&mvals., &_i., |); | |
/* Create dummies */ | |
&newvar.&_v. = (&var. eq &_v.); | |
%end; | |
run; | |
%mend; | |
/* Create year and industry dummies */ | |
%createDummyVars(dsin=da.b_funda, var=fyear, newvar=yr); | |
%createDummyVars(dsin=da.b_funda, var=sic2, newvar=ind); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment