Search code examples
sasstatisticsregressiondummy-variable

How can I generate dummy variables manually?


Here is the freq procedure:

freq procedure

Why are the TRD_EVENT_ROUFOR_1 & TRD_EVENT_ROUFOR_2 columns totally zero? Why hasn't it shown the other dummies (ex. TRD_EVENT_ROUFOR_8)? What is the problem? Which part of my code is wrong?

Here is my code?

 DATA Sampledata87_02_Mer_DumVar;
  SET Sampledata87_02_Mer ;

    IF TRD_EVENT_ROUFOR = '9:00' THEN TRD_EVENT_ROUFOR_1 = 1; 
    ELSE TRD_EVENT_ROUFOR_1 = 0;
    IF TRD_EVENT_ROUFOR = '9:30' THEN TRD_EVENT_ROUFOR_2 = 1; 
    ELSE TRD_EVENT_ROUFOR_2 = 0;
    IF TRD_EVENT_ROUFOR = '10:00' THEN TRD_EVENT_ROUFOR_3 = 1; 
    ELSE TRD_EVENT_ROUFOR_3 = 0;
    IF TRD_EVENT_ROUFOR = '10:30' THEN TRD_EVENT_ROUFOR_4 = 1; 
    ELSE TRD_EVENT_ROUFOR_4 = 0;
    IF TRD_EVENT_ROUFOR = '11:00' THEN TRD_EVENT_ROUFOR_5 = 1; 
    ELSE TRD_EVENT_ROUFOR_5 = 0;
    IF TRD_EVENT_ROUFOR = '11:30' THEN TRD_EVENT_ROUFOR_6 = 1; 
    ELSE TRD_EVENT_ROUFOR_6 = 0;
    IF TRD_EVENT_ROUFOR = '12:00' THEN TRD_EVENT_ROUFOR_7 = 1; 
    ELSE TRD_EVENT_ROUFOR_7 = 0;
    IF TRD_EVENT_ROUFOR = '12:30' THEN TRD_EVENT_ROUFOR_8 = 1; 
    ELSE TRD_EVENT_ROUFOR_8 = 0;
    IF TRD_EVENT_ROUFOR = '13:00' THEN TRD_EVENT_ROUFOR_9 = 1; 
    ELSE TRD_EVENT_ROUFOR_9 = 0;
RUN;

PROC FREQ DATA=Sampledata87_02_Mer_DumVar;
  TABLES TRD_EVENT_ROUFOR*TRD_EVENT_ROUFOR_1*TRD_EVENT_ROUFOR_2*TRD_EVENT_ROUFOR_3*TRD_EVENT_ROUFOR_4*TRD_EVENT_ROUFOR_5 / list ;
RUN;

And, here is the CONTENTS Procedure:

CONTENTS Procedure


Solution

  • For the first two variables '9:00' and '9:30' I'll guess these are right justified in the character variable $5. and are actually ' 9:00' and ' 9:30'.

    Usually you don't need to create dummies in SAS you can use the CLASS statement instead. If you do want to create them there are two procedures that are helpful PROC GLMMOD and PROC TRANSREG.

    Including example data is usually helpful.