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

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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.

Peter_C
Rhodochrosite | Level 12
One handy feature that would support this kind of connection is the USER FORMAT
This can supply a value where nunbers fall within ranges.
See PROC FORMAT

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1855 views
  • 3 likes
  • 3 in conversation