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;
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;
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;
thnak you! you got it.
What if you don't know how many levels and/or you have many variables?
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;
The answer to my question is PROC TRANSREG or PROC GLMMOD. :smileyplain:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.