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:

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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