Let's say I have 100 Temporary Employees, variable label TE, and they are assigned a number 1 -100. I want to assign the Temp Employ a Rotation number, variable label RO, of 1 through 3 repeatedly and have it start with a random rotation number. So if the random number generated for the first TE is RO = 2, I want the next RO=3, then start the cycle over of assigning RO of 1-3 for the rest of the TEs. I know this is basic, but I am struggling how to write this.
here is my example:
Data haveemp;
INPUT TE;
Datalines;
1
2
3
4
5
6
7
8
9
10
11
12
;
data wantrot;
length RO 8;
set haveemp;
if TE = 1 then RO = ceil(4*ranuni(0));
Do i = 2 to 12;
...
end;
run;
I am not sure what to do after the do statement. I have a mod(n-1,3)+1 type of thinking for the other ROs but I am not sure how to ensure a proper cycle with the random number generated for the first TE.
Any help would be appreciated.
Maybe something like this:
127 data want; 128 set haveemp; 129 retain RO; 130 if TE=1 then RO=ceil(3*ranuni(0)); 131 else RO=mod(RO,3)+1; 132 put _all_; 133 run; TE=1 RO=3 _ERROR_=0 _N_=1 TE=2 RO=1 _ERROR_=0 _N_=2 TE=3 RO=2 _ERROR_=0 _N_=3 TE=4 RO=3 _ERROR_=0 _N_=4 TE=5 RO=1 _ERROR_=0 _N_=5 TE=6 RO=2 _ERROR_=0 _N_=6 TE=7 RO=3 _ERROR_=0 _N_=7 TE=8 RO=1 _ERROR_=0 _N_=8 TE=9 RO=2 _ERROR_=0 _N_=9 TE=10 RO=3 _ERROR_=0 _N_=10 TE=11 RO=1 _ERROR_=0 _N_=11 TE=12 RO=2 _ERROR_=0 _N_=12
I like PROC PLAN for this.
Maybe something like this:
127 data want; 128 set haveemp; 129 retain RO; 130 if TE=1 then RO=ceil(3*ranuni(0)); 131 else RO=mod(RO,3)+1; 132 put _all_; 133 run; TE=1 RO=3 _ERROR_=0 _N_=1 TE=2 RO=1 _ERROR_=0 _N_=2 TE=3 RO=2 _ERROR_=0 _N_=3 TE=4 RO=3 _ERROR_=0 _N_=4 TE=5 RO=1 _ERROR_=0 _N_=5 TE=6 RO=2 _ERROR_=0 _N_=6 TE=7 RO=3 _ERROR_=0 _N_=7 TE=8 RO=1 _ERROR_=0 _N_=8 TE=9 RO=2 _ERROR_=0 _N_=9 TE=10 RO=3 _ERROR_=0 _N_=10 TE=11 RO=1 _ERROR_=0 _N_=11 TE=12 RO=2 _ERROR_=0 _N_=12
Thanks, yes that worked.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.