When an employee opens a dossier, a few tasks are created automatically. These tasks receive a sequence number (1 to 5) indicating in which order they need to be performed. Only one task can be active while the others are waiting. When a task is completed it becomes done, unless they cancel it. Each task has a start date, a close date and a deadline depending on each task. I received an Excel file which contains task_handler (employee), object_name (title of the task), start_date, close_date, deadline, task_state and sequence. object_name deadline start_date close_date task_handler task_state sequence Intake 8/03/2016 1/03/2016 7/03/2016 Handler A DONE 1 Intake 8/03/2016 1/03/2016 7/03/2016 Handler A DONE 1 Intake 8/03/2016 1/03/2016 22/03/2016 Handler B DONE 1 Intake 8/03/2016 1/03/2016 4/03/2016 Handler C DONE 1 Intake 8/03/2016 1/03/2016 9/03/2016 Handler D DONE 1 Intake 8/03/2016 1/03/2016 22/03/2016 Handler E DONE 1 Intake 8/03/2016 1/03/2016 Handler F ACTIVE 1 Intake 8/03/2016 1/03/2016 Handler G ACTIVE 1 Intake 8/03/2016 1/03/2016 Handler H ACTIVE 1 I have to make a table in which I can show how many "intakes" an employee has closed and how many "intakes" an employee still has opened. In addition, they also want me to display how many of these tasks were closed after the deadline expired. (Obviously this part requires me to focus on task_state ACTIVE and DONE.) I also have to add a final column that displays how many tasks have been CANCELLED. Important note: Employees are able to adjust the sequence of tasks, which means that I cannot reply on sequence value 1. Instead I use "like '%intake%'". If the task is cancelled, the deadline, the start_date and the close_date are empty cells. If the task is still active, the close_date is an empty cell. The result should look like this: task_handler task_state amount_of_tasks expired Handler A ACTIVE 4 0 Handler A DONE 5 1 Handler A CANCELLED 1 0 Handler B ACTIVE 3 0 Handler B DONE 9 5 Handler B CANCELLED 0 0 This is the query I created so far: (Import Excel file into SAS library.) PROC IMPORT OUT= ATROPOS.Tasks DATAFILE= "random_location" DBMS=XLS REPLACE; GETNAMES=YES; DATAROW=2; GUESSINGROWS=696430; RUN; (Add a column called Expired, which contains close_date - deadline.) PROC SQL; CREATE TABLE Atropos.TasksEXP AS SELECT *, (close_date - deadline) AS Expired FROM ATROPOS.Tasks; QUIT; (Creating the table and adjusting Expired values. (Expired > 0 = Yes // Expired <= 0 = No)) PROC SQL; CREATE TABLE ATROPOS.Startup AS SELECT task_handler, task_state, COUNT(*) AS amount_of_tasks, Expired FROM ATROPOS.Tasks WHERE task_state IN ('ACTIVE','DONE','CANCELLED') AND object_name LIKE '%Intake%' AND IF (Expired > 0) THEN (Expired = 'Yes') ELSE (Expired = 'No') GROUP BY task_handler, task_state; QUIT; I am having issues getting the IF THEN ELSE statement to work. IF remains unrecognized in a black font, whereas THEN and ELSE are recognized in a blue font. I have tried different notations, even without using brackets, but nothing appears to be working. Secondly, I find it difficult to adjust the values in Expired, even if I were to use a data or update statement. Any ideas? I am guessing I am using a very devious method or was I on the right track here? Thanks in advance.
... View more