SAS Procedures

Help using Base SAS procedures
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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