LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 11 Dec 2004 14:50:04 -0700
Reply-To:     Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject:      Re: newbie - avg time / avg charge betwn visits???
Comments: To: haleyjo@GMAIL.COM
Content-Type: text/plain; charset=us-ascii

Use the DATEPART function to get the date part of a SAS datetime value. Use the LAG function to get the difference in value between two data step iterations (an oversimplification of what LAG does, but it suffices for this usage).

Here's a sample program:

===== data visits; infile cards firstobs=2; input @1 member_no $4. @15 visit_dt datetime. @43 visit_chg 5.; visit_da = datepart(visit_dt); format visit_da date9. visit_chg 5.2; drop visit_dt; cards; Member_no Visit_dt Visit_Chg 0001 22MAR2002:00:00:00 20.00 0001 22MAY2002:00:00:00 2.00 0001 22JUL2003:00:00:00 70.00 0001 22AUG2003:00:00:00 2.00 0001 22JAN2004:00:00:00 70.00 0002 29JUN2002:00:00:00 1.00 0002 15DEC2003:00:00:00 4.00 0003 22MAR2001:00:00:00 20.00 0003 22MAY2002:00:00:00 2.00 0003 22JUN2003:00:00:00 70.00 0003 29JUL2003:00:00:00 1.00 0003 15DEC2003:00:00:00 4.00 ;;;;

proc sort data=visits; by member_no visit_da; run;

data visit_sum; set visits; by member_no; prev_da = lag(visit_da); prev_chg = lag(visit_chg); format prev_da date9. prev_chg 5.2; if first.member_no then do; visit_no = 0; prev_da = .; prev_chg = .; end; visit_no + 1; day_diff = visit_da - prev_da; chg_diff = visit_chg - prev_chg; format day_diff 4.0 chg_diff 6.2; put (_all_) (=); run;

proc summary data=visit_sum nway missing; class visit_no; var day_diff chg_diff; output out=diffs (drop=_type_ _freq_) mean=; run;

options nocenter;

title 'Proc SUMMARY Results';

proc print data=diffs; run;

title 'Proc REPORT Results';

proc report data=visit_sum nowindows; column visit_no day_diff chg_diff; define visit_no / group; define day_diff / mean width=8; define chg_diff / mean width=8; run; =====

It produces this output:

===== Proc SUMMARY Results

Obs visit_no day_diff chg_diff

1 1 . . 2 2 340 -11.00 3 3 411 68.00 4 4 34 -68.50 5 5 146 35.50

Proc REPORT Results

visit_no day_diff chg_diff 1 . . 2 340 -11.00 3 411 68.00 4 34 -68.50 5 146 35.50 =====

Note that I produced the final result in two ways: one using PROC SUMMARY and PROC PRINT, the only using PROC REPORT. You'd want to pick one method.

The program could use some fine tuning; for example, since you know that some calculations will produce missing values, you might want to use an IF to suppress those calculations and the associated error messages. If wanted to get fancy, you could do all of the calcuations in a single data step instead of a data step plus a proc. You might even be able to do everything in a single PROC REPORT with no data step - would someone like to step up to the challenge?

-- JackHamilton@FirstHealth.com Manager, Technical Development Metrics Department, First Health West Sacramento, California USA

Coelum, non animum mutant, qui trans mare currunt.

>>> "haleyjo" <haleyjo@GMAIL.COM> 12/11/2004 12:20 PM >>> I have data similar to the following for our medical office:

Member_no Visit_dt Visit_Chg 0001 22MAR2002:00:00:00 20.00 0001 22MAY2002:00:00:00 2.00 0001 22JUL2003:00:00:00 70.00 0001 22AUG2003:00:00:00 2.00 0001 22JAN2004:00:00:00 70.00 0002 29JUN2002:00:00:00 1.00 0002 15DEC2003:00:00:00 4.00 0003 22MAR2001:00:00:00 20.00 0003 22MAY2002:00:00:00 2.00 0003 22JUN2003:00:00:00 70.00 0003 29JUL2003:00:00:00 1.00 0003 15DEC2003:00:00:00 4.00

I want to find avg time between visits and avg cost between visits. In other words, avg time between 1st visit and second visit (overall), avg time between 2nd and 3rd, 3rd and 4th, 4th and 5th visits, etc. Then, similarly, avg charge between 1st visit and second visit (overall), etc.

I have been reading about first. and last. - but not sure how to get the 2nd, 3rd and 4th. Just not sure where to begin. I need to make each visit a varible, right? Would proc transpose help me? I also need to get rid of the hrs, min, sec on the dates. someone point me in the right direction? thankyou. haleyjo

"MMS <firsthealth.com>" made the following annotations. ------------------------------------------------------------------------------ This message, including any attachments, is intended solely for the use of the named recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure or distribution of this communication(s) is expressly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy any and all copies of the original message. Thank you. =============================================================================


Back to: Top of message | Previous page | Main SAS-L page