BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jkf91
Calcite | Level 5

I have data with month variable. For each month, I want to create a dummy variable. Can someone tell me how I can do this automatically?

I think teh following should do the job, but it doesn't. Anyone knows why?

THanks,

C

DATA auto3;

  set auto3;

  ARRAY dummys {*} 8.  month_1 - month_12;

  DO i=1 TO 12;                                   

  dummys(i) = 0;

  END;

  dummys(month) = 1;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You will have to post what auto3 initially looks like and be more specific about what you want to achieve.

The way your code is written, the twelve variables month_1-month_12 would have to already exist.  You may be looking for something like:

DATA auto3;

  set auto3;

  ARRAY month_ {12};

  DO i=1 TO 12;                                  

    month_(i) = ifn(i=month,1,0);

  END;

RUN;

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

You will have to post what auto3 initially looks like and be more specific about what you want to achieve.

The way your code is written, the twelve variables month_1-month_12 would have to already exist.  You may be looking for something like:

DATA auto3;

  set auto3;

  ARRAY month_ {12};

  DO i=1 TO 12;                                  

    month_(i) = ifn(i=month,1,0);

  END;

RUN;

jkf91
Calcite | Level 5

thnak you! you got it.

data_null__
Jade | Level 19

What if you don't know how many levels and/or you have many variables?

MikeZdeb
Rhodochrosite | Level 12

Hi ... maybe you can skip the loop and only change one value per observation (doesn't answer _null_'s question) ...

data auto3;

array month_(12) (12*0);

set auto3;

month_(month) = 1;

output;

month_(month) = 0;

run;

data_null__
Jade | Level 19

The answer to my question is PROC TRANSREG or PROC GLMMOD. :smileyplain:

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1699 views
  • 0 likes
  • 4 in conversation