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

I have a two part question (sample data attached)

I have a file with admission and discharge dates, some have multiple admissions and discharges.

What would be the best way to code to determine:

 

- if the multiple admission and discharge dates are consecutive (chronological) or not

- if the dates overlap (for example if a patients first admission date is 1/1/2022 and the discharge is 1/3/2022 but their second admission date is 1/2/2022 and the second discharge is 1/4/2022)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

What helps us help you is if you provide sample data in the form of a fully working "have" data step as done below. Then show us the desired result based on your sample data. 

It's easy enough to generate a "have" dataset from an Excel or text source using the SAS EG or SAS Studio import wizards (with embed data selected).

The Excel data you've provided appears to not have a single case with overlapping date ranges - so I had to make one up.

 

data work.have;
  infile datalines4
    dlm='|'
    truncover
    dsd 
    ;
  format
    ID                 best12.
    ICU_AdmitDate      date9.
    ICU_AdmitDate2     date9.
    ICU_AdmitDate3     date9.
    ICU_DischargeDate  date9.
    ICU_DischargeDate2 date9.
    ICU_DischargeDate3 date9. 
    ;
  input
    ID                  : 32.
    ICU_AdmitDate       : date9.
    ICU_AdmitDate2      : date9.
    ICU_AdmitDate3      : date9.
    ICU_DischargeDate   : date9.
    ICU_DischargeDate2  : date9.
    ICU_DischargeDate3  : date9.
    ;
  datalines4;
1|04APR2021|10APR2021|.|07APR2021|10APR2021|.
2|18OCT2021|25OCT2021|05NOV2021|25OCT2021|05NOV2021|27NOV2021
3|29JUL2021|.|.|10SEP2021|.|.
4|27JUN2020|.|.|14JUL2020|.|.
5|26DEC2020|.|.|28DEC2020|.|.
6|20JAN2021|21JAN2021|.|22JAN2021|02FEB2021|.
7|30MAR2020|.|.|11APR2020|.|.
8|23APR2021|.|.|25APR2021|.|.
9|17JAN2021|.|.|05FEB2021|.|.
10|29DEC2020|12JAN2021|.|29DEC2020|22JAN2021|.
;;;;

data want;
  overlap_flg=0;
  set have;
  array admit {*} ICU_AdmitDate ICU_AdmitDate2 ICU_AdmitDate3;
  array disch {*} ICU_DischargeDate ICU_DischargeDate2 ICU_DischargeDate3;

  do i=2 to dim(admit) while (not missing(admit[i]));
    if disch[i-1]>admit[i] then 
      do;
        overlap_flg=1;
        leave;
      end;
  end;
run;

View solution in original post

3 REPLIES 3
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software or policy. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values (especially dates).

 

Provide example data in the forum of data step code.

 

Also provide what you expect the output to look like.

carmong
Obsidian | Level 7

An example of my data is as follows:

 

IDICU_AdmitDateICU_AdmitDate2ICU_AdmitDate3ICU_DischargeDateICU_DischargeDate2ICU_DischargeDate3
14-Apr-2110-Apr-21.7-Apr-2110-Apr-21.
218-Oct-2125-Oct-215-Nov-2125-Oct-215-Nov-2127-Nov-21
Patrick
Opal | Level 21

What helps us help you is if you provide sample data in the form of a fully working "have" data step as done below. Then show us the desired result based on your sample data. 

It's easy enough to generate a "have" dataset from an Excel or text source using the SAS EG or SAS Studio import wizards (with embed data selected).

The Excel data you've provided appears to not have a single case with overlapping date ranges - so I had to make one up.

 

data work.have;
  infile datalines4
    dlm='|'
    truncover
    dsd 
    ;
  format
    ID                 best12.
    ICU_AdmitDate      date9.
    ICU_AdmitDate2     date9.
    ICU_AdmitDate3     date9.
    ICU_DischargeDate  date9.
    ICU_DischargeDate2 date9.
    ICU_DischargeDate3 date9. 
    ;
  input
    ID                  : 32.
    ICU_AdmitDate       : date9.
    ICU_AdmitDate2      : date9.
    ICU_AdmitDate3      : date9.
    ICU_DischargeDate   : date9.
    ICU_DischargeDate2  : date9.
    ICU_DischargeDate3  : date9.
    ;
  datalines4;
1|04APR2021|10APR2021|.|07APR2021|10APR2021|.
2|18OCT2021|25OCT2021|05NOV2021|25OCT2021|05NOV2021|27NOV2021
3|29JUL2021|.|.|10SEP2021|.|.
4|27JUN2020|.|.|14JUL2020|.|.
5|26DEC2020|.|.|28DEC2020|.|.
6|20JAN2021|21JAN2021|.|22JAN2021|02FEB2021|.
7|30MAR2020|.|.|11APR2020|.|.
8|23APR2021|.|.|25APR2021|.|.
9|17JAN2021|.|.|05FEB2021|.|.
10|29DEC2020|12JAN2021|.|29DEC2020|22JAN2021|.
;;;;

data want;
  overlap_flg=0;
  set have;
  array admit {*} ICU_AdmitDate ICU_AdmitDate2 ICU_AdmitDate3;
  array disch {*} ICU_DischargeDate ICU_DischargeDate2 ICU_DischargeDate3;

  do i=2 to dim(admit) while (not missing(admit[i]));
    if disch[i-1]>admit[i] then 
      do;
        overlap_flg=1;
        leave;
      end;
  end;
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 855 views
  • 3 likes
  • 3 in conversation