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:
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.