Create dummy from categoric variables
9. May 2007 04:41Dummy Variables:
A dummy variable is a numerical variable used in regression analysis to represent subgroups of the sample in your study.In the simplest case, we would use a 0,1 dummy variable where a person is given a value of 0 if they are in the control group or a 1 if they are in the treated group. Dummy variables are useful because they enable us to use a single regression equation to represent multiple groups. This means that we don't need to write out separate equation models for each subgroup.
data test;
input a b;
datalines;
1 3
2 4
7 5
1 3
2 4
7 5
;
run;
proc means data=test;
var a b;
output out=toz min= max=/autoname;
run;
data _null_;
set toz;
call symput('a_min',a_min);
call symput('a_max',a_max);
run;
%macro recode(myvar, num1, num2);
array &myvar._a(*) &myvar.&num1 - &myvar.&num2;
do i = &num1 to &num2;
&myvar._a(i - &num1 + 1 ) = .;
end;
do i = &num1 to &num2;
if (&myvar = i) then &myvar._a(i - &num1 + 1 ) = 1;
if (&myvar > .) and (&myvar ~= i) then &myvar._a(i - &num1 + 1) = 0;
end;
%mend;
options mprint mlogic;
data test2;
set test;
%recode(a, &a_min, &a_max);
run;
%recode(b, 3, 5);
drop i;
run;

Email 