Hi,
I'm trying to write codes for a loop to simulate Arrivals and Departures. There's only one server (M/M/1) and it is a FCFS. So if someone arrives when the server is busy, then they have to wait for the server to be free.
data have;
input id time_of_arrival service_time;
datalines;
1 1.5 2
2 2 1
3 3.5 2
4 8 1
5 10 2
6 12 1
7 13 2
8 14 2
9 16 3
run;
data have;
set have;
time_of_leaving = time_of_arrival + service_time;
lag_time_of_leaving = lag(time_of_leaving);
if lag_time_of_leaving > time_of_arrival then flag = 1; else flag = 0;
run;
I thought about creating another variable = 0 (flag2) and loop until flag = flag2 (see following code - it added it before the run; command in the previous code). However, the program has been running for the past hour and my initial thought is that there must be a more efficient way of doing it.
flag2 = 0;
do until (flag = flag2);
if flag = 1 then time_of_leaving = lag_time_of_leaving + service_time;
lag_time_of_leaving = lag(time_of_leaving);
if lag_time_of_leaving > time_of_arrival then flag = 1; else flag = 0;
end;
In the end, I'd like for the results to be as followed
id | time_of_arrival | service_time | time_of_leaving |
1 | 1.5 | 2 | 3.5 |
2 | 2 | 1 | 4.5 (server is free at 3.5 + service_time of 1) |
3 | 3.5 | 2 | 6.5 |
4 | 8 | 1 | 9 |
5 | 10 | 2 | 12 |
6 | 12 | 1 | 13 |
7 | 13 | 2 | 15 |
8 | 14 | 2 | 17 |
9 | 16 | 3 | 20 |
Thank you in advance for your help
data have;
input id time_of_arrival service_time;
retain want;
want=ifn(time_of_arrival<want,want+service_time,time_of_arrival+service_time);
datalines;
1 1.5 2
2 2 1
3 3.5 2
4 8 1
5 10 2
6 12 1
7 13 2
8 14 2
9 16 3
run;
I don't fully understand this.
Can you post what your desired result looks like?
data have;
input id time_of_arrival service_time;
retain want;
want=ifn(time_of_arrival<want,want+service_time,time_of_arrival+service_time);
datalines;
1 1.5 2
2 2 1
3 3.5 2
4 8 1
5 10 2
6 12 1
7 13 2
8 14 2
9 16 3
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.