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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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