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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

I like PROC PLAN for this.

data _null_;
  
call streaminit(34567);
   call symputx('ib',rand('table',1/3,1/3));
   run;
%put NOTE: &=ib &=sysrandom;

proc plan seed=998877;
  
factors to=100 ordered ro=1 of 3 cyclic(&ib) /noprint;
  
output out=plan;
   run;
  
quit;
proc print;
  
run;

6-10-2015 12-32-46 PM.png
Quentin
Super User

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

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
jprosenbaum8908
Calcite | Level 5

Thanks, yes that worked.

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
  • 3 replies
  • 861 views
  • 3 likes
  • 3 in conversation