Help using Base SAS procedures

Calculating mean length of stay in hours using SAS datetime var

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Calculating mean length of stay in hours using SAS datetime var

Hi All,

I am stuck!

i have created a variable "edtime" which is in hours and minutes and is the length of stay in ED from arrival to discharge, please see code below:

data ten;

set nine;

edtime=(EDdischarge_sasdt-EDarrival_sasdt);

format edtime hhmm5.;

label edtime ='length of stay in ED from arrival to discharge';

run;

Now, I would like to calculate  the mean "edtime" By three time periods, Where two variables are (1),. How do I do this? I tried doing the following and it didn't work:

proc means data=ten q1 q3 qrange n sum std mean median clm cv min max;

var edtime;

class timeperiod;

where ltcfgroup in (1) and edtransfergroup in (1);

run;

output:

                      The MEANS Procedure

              Analysis Variable : edtime length of

              stay in ED from arrival to discharge

Time Period

    for both

   acute and

ltcf merged

       data:

(1)=time one

    (2)=time

two (3)=time    N         Lower         Upper      Quartile

       three  Obs      Quartile      Quartile         Range    N

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

           1  148      14490.00      35490.00      21000.00  148

           2  122      15360.00      34200.00      18840.00  122

           3  158      17280.00      39840.00      22560.00  158

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

              Analysis Variable : edtime length of

              stay in ED from arrival to discharge

  Time Period

     for both

    acute and

  ltcf merged

        data:

(1)=time one

     (2)=time

two (3)=time    N

        three  Obs           Sum        Std Dev           Mean

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

            1  148    4740660.00       55311.91       32031.49

            2  122    3492360.00       20520.31       28625.90

            3  158    4976099.00       23854.52       31494.30

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

          The MEANS Procedure

              Analysis Variable : edtime length of

              stay in ED from arrival to discharge

  Time Period

     for both

    acute and

  ltcf merged

        data:

(1)=time one

     (2)=time

two (3)=time    N                    Lower 95%      Upper 95%

        three  Obs        Median    CL for Mean    CL for Mean

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

            1  148      22110.00       23046.32       41016.65

            2  122      23670.00       24947.85       32303.95

            3  158      23880.00       27745.86       35242.74

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

              Analysis Variable : edtime length of

              stay in ED from arrival to discharge

  Time Period

     for both

    acute and

  ltcf merged

        data:

(1)=time one

     (2)=time

two (3)=time    N      Coeff of

        three  Obs     Variation        Minimum        Maximum

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

            1  148   172.6798061        2640.00      658680.00

            2  122    71.6844075        1620.00      116940.00

            3  158    75.7423416        3300.00      174420.00

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Any help would be very helpful. I am not sure I can even perform a proc means with sas datetime variables. Also, is there some formatting that needs to happen?

Thanks!!!


Accepted Solutions
Solution
‎11-22-2013 03:17 PM
Respected Advisor
Posts: 4,925

Re: Calculating mean length of stay in hours using SAS datetime var

The problem is that you loose your time format in the MEANS output. To keep the format, try instead:

proc means data=ten;
var edtime;
class timeperiod;
where ltcfgroup in (1) and edtransfergroup in (1);
output out=tenStats q1= q3= qrange= n= sum= std= mean= median= clm= cv= min= max= / autoname;
run;

proc print data=tenStats noobs; run;

PG

PG

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: Calculating mean length of stay in hours using SAS datetime var

is your data sorted by timeperiod? if not try changing "by timeperiod;" to "class timeperiod;"

Occasional Contributor
Posts: 16

Re: Calculating mean length of stay in hours using SAS datetime var

i will do that, but it still doesn't give me a mean or anything of use for proc means. any other suggestions?

Solution
‎11-22-2013 03:17 PM
Respected Advisor
Posts: 4,925

Re: Calculating mean length of stay in hours using SAS datetime var

The problem is that you loose your time format in the MEANS output. To keep the format, try instead:

proc means data=ten;
var edtime;
class timeperiod;
where ltcfgroup in (1) and edtransfergroup in (1);
output out=tenStats q1= q3= qrange= n= sum= std= mean= median= clm= cv= min= max= / autoname;
run;

proc print data=tenStats noobs; run;

PG

PG
Occasional Contributor
Posts: 16

Re: Calculating mean length of stay in hours using SAS datetime var

THANK YOU SOOO MUCH!!!!

I figured it was a formatting issue but couldnt figure it out.

Thanks again!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1007 views
  • 3 likes
  • 3 in conversation