Please, I need help with an algorithm for evaluating the order in which patients were picked from a waiting rooming. The algorithm will assign a group of patients to a waiting room according to the time they were waiting to see the physician. Patients who are assigned to a physician are compared to other patients still in the waiting room to see if they were picked in order. They are picked in order if they are sicker than other patients in the waiting room as measured by a severity of illness variable called acuity. it ranges from 1-5 with 1 being the sickest. If there were in the room with another patient with the same acuity, then whoever was waiting longer should be seen first. If they were seen in other, then there was 'no violation' but if they were seen before a sicker patient who was also waiting then there was an 'acuity violation.' In addition, if there were seen before a patient who had same acuity and had waited longer, then there was a 'time violation'. I tried creating blocks of waiting time but noticed that some patients had waiting times that spanned several blocks. This means a patient could move into another block if not picked in their initial block. The whole idea is to evaluate if there was a violation when a patient was picked from the waiting room to see a physician when compared to other patients who were with him in the waiting room based on severity of illness and waiting time. I am stuck at this point. Please kindly help.
* Create date interval;
data DATE_INTERVAL;
FORMAT DATE_START DATE9.;
DATE_START = '31MAY2019'D;
DO LOOP = 0 TO 365 BY 1;
OUTPUT;
END;
RUN;
DATA DATE_INTERVAL2;
SET DATE_INTERVAL;
DATE = DATE_START + LOOP;
FORMAT DATE DATE9.;
DROP LOOP DATE_START;
run;
* import sample data;
PROC IMPORT DATAFILE= 'R:\data\subset data.xlsx'
DBMS = XLSX
OUT= patients
REPLACE;
SHEET='Sheet1';
RUN;
DATA PATIENTS2;
SET PATIENTS;
* This step changes the date in datetime from character to numeric;
ROOMED2=input(ROOMED, anydtdtm.);
ASSIGNED2=input(Provider_Assigned, anydtdtm.);
* This pulls out the DATE from the datetime variables;
DATE=datepart(ROOMED2);
ROOMDATE = datepart(ROOMED2);
ASSIGNDATE=datepart(ASSIGNED2);
* This pulls out the TIME from the datetime variables;
ROOMTIME=TIMEPART(ROOMED2);
ASSIGNEDTIME=TIMEPART(ASSIGNED2);
DROP ROOMED PROVIDER_ASSIGNED ROOMED2 PROVIDER_ASSIGNED ASSIGNED2;
FORMAT DATE ROOMDATE ASSIGNDATE DATE9.;
format ROOMTIME ASSIGNEDTIME HHMM.;
RUN;
PROC SORT DATA = PATIENTS2; BY DATE; RUN;
PROC SORT DATA = DATE_INTERVAL2; BY DATE; RUN;
DATA WAITINGROOM;
MERGE PATIENTS2 (IN = A) DATE_INTERVAL2 (IN = B);
BY DATE;
IF Obs = . THEN DELETE;
do loop=0 to 1430 by 10;
start = intnx('dtminute', '00:00:00't, loop); output;
end = intnx('dtminute', '00:10:00't, loop); output;
end;
format start end HHMM.;
DROP LOOP;
RUN;
PROC SORT DATA = WAITINGROOM; BY ROOMDATE ASSIGNDATE; RUN;
DATA WAITINGROOM2;
SET WAITINGROOM;
BY ROOMDATE ASSIGNDATE;
/*IF START = . THEN DELETE;
IF END = . THEN DELETE;
IF START = END THEN DELETE;**/
IF ROOMTIME GE START AND ROOMTIME LT END THEN WAITINGROOM = 1;
IF ASSIGNEDTIME GE START AND ASSIGNEDTIME LT END THEN WAITINGROOM = 1;
IF ROOMTIME LT START AND ASSIGNEDTIME GE END THEN WAITINGROOM = 1;
IF WAITINGROOM = 1;
WAITINGROOMBLOCK = CATX(ROOMDATE, ASSIGNDATE, START, END);
RUN;
PROC SORT DATA = WAITINGROOM2 OUT = BLOCKS NODUPKEY; BY WAITINGROOMBLOCK; RUN;
DATA BLOCKS2;
SET BLOCKS;
BY WAITINGROOMBLOCK;
BLOCK + 1;
KEEP WAITINGROOMBLOCK BLOCK;
RUN;
PROC SORT DATA = WAITINGROOM2; BY WAITINGROOMBLOCK; RUN;
PROC SORT DATA = BLOCKS2; BY WAITINGROOMBLOCK; RUN;
DATA BLOCKS3;
MERGE WAITINGROOM2 BLOCKS2;
BY WAITINGROOMBLOCK;
DROP WAITINGROOM WAITINGROOMBLOCK;
IF ASSIGNEDTIME GE START AND ASSIGNEDTIME LT END THEN SELECTION = 1;
RUN;
DATA BLOCKEXAMPLE;
SET BLOCKS3;
IF BLOCK GE 17 AND BLOCK LE 20;
RUN;
PROC SORT DATA = BLOCKEXAMPLE; BY BLOCK ACUITY WAITING_TIME; RUN;
DATA BLOCKEXAMPLE2;
SET BLOCKEXAMPLE;
BY BLOCK ACUITY ;
RETAIN ORDER_EXPECTED;
IF FIRST.BLOCK THEN DO;
ORDER_EXPECTED = 0;
END;
ORDER_EXPECTED + 1;
DROP
RUN;
* THIS PART NEEDS TO BE FIXED;
PROC SORT DATA = BLOCKEXAMPLE2; BY BLOCK DESCENDING WAITING_TIME; RUN;
DATA BLOCKEXAMPLE3;
SET BLOCKEXAMPLE2;
BY BLOCK ;
RETAIN ORDER_ACTUAL;
IF FIRST.BLOCK THEN DO;
ORDER_ACTUAL = 0;
END;
ORDER_ACTUAL + 1;
RUN;
could you provide a sample of table patients?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.