Hi there, I have 50 categorical variables for which I need to create dummy variables for each level of response. For instance, variable Q1 has 3 levels: 1,2,3. The macro DUMMYLEVEL below will create 3 dummy variables for Q1: Q1_1, Q1_2, and Q1_3. My codes below-- which invokes the macro DUMMYLEVEL twice in the DATA step-- produces the following error message: "ERROR 124-185: The variable D has already been defined." This error only occurs when the macro DUMMYLEVEL is called more than once in the DATA step. Anybody have experience working around this error to achieve my goal of creating dummy variables for 50 categorical variables? Thank you! /* Macro to create dummy variables for ROOT variable with NUM levels */ %MACRO DUMMYLEVEL (ROOT= , NUM= ); ARRAY D(*) &ROOT._1 - &ROOT._&NUM. (&NUM.*0); IF &ROOT. NE . THEN D(&ROOT.)= 1; OUTPUT; IF &ROOT. NE . THEN D(&ROOT.)= 0; %MEND; /* Sample DATA step: call macro DUMMYLEVEL twice */ DATA OUT; SET IN (KEEP= ID Q1--Q50); %Dummylevel (root= Q1, num= 3); %Dummylevel (root= Q2, num= 2); RUN;
... View more