Date: Sat, 23 Oct 2004 07:48:24 -0700
Reply-To: Bill McKirgan maxsfolks <bill-mckirgan@UIOWA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bill McKirgan maxsfolks <bill-mckirgan@UIOWA.EDU>
Organization: http://groups.google.com
Subject: Re: calculate the time between cancelation of 2 contracts on the
household-level
Content-Type: text/plain; charset=ISO-8859-1
Stefan,
Summarizing across records is an area I need to practice more,
and so this thread naturally caught my interest.
Toby's "untested" code had one minor flaw, but still did the job
of holding the desired values within the householdid group.
While the correct values were retained I found one error
in the part where the differences were calculated:
Last_date = householdid
--should be--
Last_date = canceldate
Toby's example used INTCK to report the interval in weeks.
Here again is an area I need more practice with, and so I
played around a bit created another variable to report
the interval in days.
Evidently the interval part of the argument takes many
variations: DAY, DAYS, WEEK, WEEKS, WEEK1.1...I tried SECONDS
but still got a DAY interval (?huh?)...I guess I will RTFM that one.
Thanks to both of you. This was a good question and example to
learn from on a Saturday morning SAS-L Zen session.
Kind regards,
Bill
---program
data a;
informat canceldate ddmmyy10.;
format canceldate ddmmyy10.;
input contractid householdid canceldate ;
datalines4;
1 1 23.11.1999
2 1 30.04.2001
3 2 01.01.2000
4 2 31.05.2001
;;;;
run;
proc sort;
by householdid cnxdate;
run;
data b; set a;
By householdid;
Retain last_date;
If not first.householdid then
days_between = intck('days',last_date,canceldate);
weeks_between= intck('weeks',last_date,canceldate);
Last_date = canceldate; format last_date ddmmyy10.;
put (_all_) (=/);
run;
---log
61 data b; set a;
62 By householdid;
63 Retain last_date;
64 If not first.householdid then
65 days_between = intck('days',last_date,canceldate);
66 weeks_between= intck('weeks',last_date,canceldate);
67 Last_date = canceldate; format last_date ddmmyy10.;
68 put (_all_) (=/);
69 run;
canceldate=23/11/1999
contractid=1
householdid=1
last_date=23/11/1999
days_between=.
weeks_between=.
canceldate=30/04/2001
contractid=2
householdid=1
last_date=30/04/2001
days_between=524
weeks_between=75
canceldate=01/01/2000
contractid=3
householdid=2
last_date=01/01/2000
days_between=.
weeks_between=-70
canceldate=31/05/2001
contractid=4
householdid=2
last_date=31/05/2001
days_between=516
weeks_between=74
NOTE: Missing values were generated as a result of performing an
operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 66:20
NOTE: There were 4 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 4 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.11 seconds
cpu time 0.08 seconds
*/Toby.Dunn@TEA.STATE.TX.US (Dunn, Toby) wrote in message news:<748343794E05734F9D9E9BBF2CA6D214621B55@LYNDON.tea.state.tx.us>...
> Stefan,
>
> AS I am not sure what type of time period you are looking for you will
> more than likely need to read up on intck function and modify it so that
> time_between gives you what you want.
>
> <Untested code follows>
>
> Data between;
> SET <your data>;
> By householdid;
> Retain last_date;
>
> If not first.householdid then
> time_between = intck('week1.1',last_date,canceldate);
>
> Last_date = householdid;
> run;
>
> HTH
> Toby Dunn
>
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Stefan Pohl
> Sent: Friday, October 22, 2004 11:50 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: calculate the time between cancelation of 2 contracts on the
> household-level
>
>
> Hi,
>
> i suppose that my problem can be solved by group by-processing...
>
> my data look like this:
>
> contractid householdid canceldate
> 1 1 23.11.1999
> 2 1 30.04.2001
> 3 2 01.01.2000
> 4 2 31.05.2001
>
> i want to caculate for each household the time between two cancelations,
> i.e. for household 1 30.04.2001 - 23.11.1999 and so on.
>
> is there an easy way ? Group by processing?
>
> thank you, stefan.