Hi group,
I have a data with Emergency Room visits with Room start date (datetime) and Room end dates. I also have labs for the patients captured as collection_date (datetime). I have to identify labs which were taken at ER using Room_Start_Date (datetime) and Room_End_Date (datetime). If labs were taken between Room_Start_Date and Room_End_Date, then they are considered labs_at_ER, which need to create a new categorical variable (yes/no). Can anyone please help me with the SAS codes to create this new variable? Note: all my date variables are in datetime format.
Thanks a lot,
Satish
Hi Satish,
Basically, the new categorical variable could be defined as follows (in a data step; similarly in PROC SQL):
labs_at_ER=(Room_Start_Date<=collection_date<=Room_End_Date);
(Assumption: Your datetime variables are SAS datetime values or at least in a format that preserves chronological order.)
As created above, labs_at_ER would be a numeric variable, to which you could assign a numeric format that maps 1 to "yes" and 0 to "no." This has several advantages over a character variable with values "yes" and "no."
It's up to you to decide if "<=" or "<" is more appropriate in either place in the definition. You should also add code (e.g. an IF condition) to handle missing values of the three variables involved in the inequality.
Edit: Correction: The numeric format should, of course, map 0 to "no", not 2.
Hi Satish,
Basically, the new categorical variable could be defined as follows (in a data step; similarly in PROC SQL):
labs_at_ER=(Room_Start_Date<=collection_date<=Room_End_Date);
(Assumption: Your datetime variables are SAS datetime values or at least in a format that preserves chronological order.)
As created above, labs_at_ER would be a numeric variable, to which you could assign a numeric format that maps 1 to "yes" and 0 to "no." This has several advantages over a character variable with values "yes" and "no."
It's up to you to decide if "<=" or "<" is more appropriate in either place in the definition. You should also add code (e.g. an IF condition) to handle missing values of the three variables involved in the inequality.
Edit: Correction: The numeric format should, of course, map 0 to "no", not 2.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.