I have written the following SAS code to create dummy variables for all my categorical variables. However the code does not see to give me a desired result.
/# creating a copy of the data set in the work library#/
libname eco "Z:\Globe\Call Data Modeling";
data model_data;
set eco.em_save_train;
run;
/#getting the names and types of variables in the data set
proc contents data= model_data out= var_names(keep=name type)noprint;
run;
/#creating a macro to create the dummy variable coding#/
%macro cat(indata, variable);
proc sql noprint;
select distinct &variable. into :mvals separated by '|'
from &indata.;
%let mdim=&sqlobs;
quit;
data &indata.;
set &indata.;
%do _i=1 %to &mdim.;
%let _v = %scan(&mvals., &_i., |);
if &variable. = &_v. then &variable.&_v. = 1; else &variable.&_v = 0;
%end;
run;
%mend;
/#calling the macro and passing the dataset name and variable name, based on the type . if type=2 then it is categorical variable#/
data _null_;
set var_names;
if type=2 then call execute('%cat(model_data,'||name||')');
run;