Date: Wed, 13 Feb 2008 11:47:39 -0600
Reply-To: Yu Zhang <zhangyu05@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Yu Zhang <zhangyu05@GMAIL.COM>
Subject: Re: Finding X's that are 10-day apart
In-Reply-To: <1202920564.47b31c7447b51@outlier.rutgers.edu>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
For any observation which dosen't has a ealier 10 days counterpart, you
will choose a close one for your calcualtion. if I understood this
correctly, here is the code to get you started.
HTH
Yu
*
DATA* S;
INPUT _DATE :yymmdd10. X;
CARDS;
2007-04-29 35.4375
2007-04-24 35
2007-04-21 34.5
2007-04-20 34.25
2007-04-17 33.5
2007-04-12 33.5
2007-04-11 32.75
2007-04-10 32
2007-04-09 31.8125
2007-04-06 31.82
2007-04-05 31.875
2007-04-02 31.875
2007-04-01 32
;
*
RUN*;
title1;
footnote1;
*
proc* *sql*;
select a._date format=mmddyy10.,a.x ,b._date as date format=mmddyy10.,b.x asx1,
a._date-b._date as diff from s as a, s as b
where a._date>=b._date and *0*<=a._date-b._date<=*10
*
group by a._date
having calculated diff=max(diff);
*
quit*;
On Feb 13, 2008 10:36 AM, Jue A. Wang <wang@stat.rutgers.edu> wrote:
> My data contains a sample of X observed during certain period of time
> (DATE).
> Part of the data is enumerated below.
>
>
> DATA S;
> INPUT _DATE $1-10 X;
> CARDS;
> 2007-04-29 35.4375
> 2007-04-24 35
> 2007-04-21 34.5
> 2007-04-20 34.25
> 2007-04-17 33.5
> 2007-04-12 33.5
> 2007-04-11 32.75
> 2007-04-10 32
> 2007-04-09 31.8125
> 2007-04-06 31.82
> 2007-04-05 31.875
> 2007-04-02 31.875
> 2007-04-01 32
> ;
> RUN;
>
>
>
> I need to create a new variable Y which is the difference between two X's
> that
> are recorded (roughly) 10 days apart, for example, the first X is
> recorded on
> 2007-4-29, so the first Y should be calculated as the X on this date minus
> the
> X on 2007-4-19
>
> =35.4375-34.25
>
> the second X is on 2007-4-24, since there is no record 10 day earlier on
> 2007-
> 4-14, I'd use the X closer to 2007-4-14 which is on 2007-4-12, so the
> second X
> =35-33.5
>
> I need your help that
>
> (1)If the data is complete that each record has a corresponding 10-day
> earlier
> record, but the distribution of DATE is not uniform(there is no pattern
> between adjacent DATE's) , then how can I create Y?
> (2)If the data is incomplete, in that not every X has a corresponding
> 10-day
> earlier X, how can I create Y?
>
>
> Thank you
>
> Andrew
>
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
>
|