Date: Mon, 14 Jan 2008 11:13:33 -0800
Reply-To: z <gzuckier@SNAIL-MAIL.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: z <gzuckier@SNAIL-MAIL.NET>
Organization: http://groups.google.com
Subject: Re: Grouping By Date
Content-Type: text/plain; charset=ISO-8859-1
On Jan 14, 8:34 am, kmor...@GRAINSCANADA.GC.CA (Kevin Morgan) wrote:
> Hello Ya:
>
> Works like a charm. I hadn't run into the Lag function yet and can see
> it coming in quite useful in a couple of upcoming projects I have.
>
> Thanks for the help
>
> Kevin
main "catch" with the lag function is you have to use it before you do
any iffing or whereing.
i.e.
data blah;
set blahblah;
foo = lag(fee);
if foo = fee then x = 1;
run;
will work, but
data blah;
set blahblah;
if fee = lag(fee) then x = 1;
run;
won't work, because sas will do the if function before it does the lag
function.
>
>
>
> -----Original Message-----
> From: Ya Huang [mailto:ya.hu...@AMYLIN.COM]
> Sent: Friday, January 11, 2008 10:43 PM
> To: SA...@LISTSERV.UGA.EDU; Kevin Morgan
>
> Cc: Ya Huang
> Subject: Re: Grouping By Date
>
> This seems to work:
>
> proc sort data=ves;
> by vessel dest tdiff;
> run;
>
> data ves;
> set ves;
> by vessel dest;
> lagt=lag(tdiff);
> if first.dest then lagt=tdiff;
> if tdiff-lagt >60 or first.dest then grp+1;
> run;
>
> proc print;
> var vessel dest tdiff grp;
> run;
>
> vessel dest tdiff grp
>
> ANTIKERI Italy 0 1
> ANTIKERI Italy 80 2
> ANTIKERI Italy 80 2
> ANTIKERI Italy 81 2
> ANTIKERI Italy 318 3
> ANTIKERI Italy 318 3
> ANTIKERI Italy 318 3
> ANTIKERI Italy 440 4
> ANTIKERI Italy 440 4
> ANTIKERI Italy 827 5
> ANTIKERI Italy 827 5
> ANTIKERI Morocco 390 6
> ANTIKERI Morocco 390 6
> ANTIKERI Morocco 391 6
> ANTIKERI Morocco 391 6
> ANTIKERI Morocco 402 6
> ANTIKERI Turkey 231 7
>
> On Fri, 11 Jan 2008 21:20:28 -0600, Kevin Morgan
> <kmor...@GRAINSCANADA.GC.CA> wrote:
>
> >Hello:
>
> >I have some data for about 1500 frigate/bulk cargo vessels that I need
> >to group by date. Below I have included an example from the vessel
> >ANTIKERI. Tdiff is the length of time from the first loading date of
> the
> >ANTIKERI. The Org field is location the vessel was loaded at EA, is
> >Montreal Canada and LH is Thunder Bay Canada. Dest is the destination
> >of the vessel.
>
> >I need SAS to group the ANTIKERI (and another 1499 other vessels, by
> >vessel) into separate loadings by date. Looking over my data I see that
> >separation between loadings is out 60 days. So a difference between
> >TDiff of greater than 60 days should give me a new group. Also
> >Destination within each grouping should also be the same. Org may or
> may
> >not be different...
>
> >Vessel Org Dest Date tdiff
> >ANTIKERI EA Italy 24/09/2005 0
> >ANTIKERI EA Italy 13/12/2005 80
> >ANTIKERI EA Italy 13/12/2005 80
> >ANTIKERI EA Italy 14/12/2005 81
> >ANTIKERI LH Turkey 13/05/2006 231
> >ANTIKERI EA Italy 8/8/2006 318
> >ANTIKERI EA Italy 8/8/2006 318
> >ANTIKERI EA Italy 8/8/2006 318
> >ANTIKERI LH Morocco 19/10/2006 390
> >ANTIKERI LH Morocco 19/10/2006 390
> >ANTIKERI LH Morocco 20/10/2006 391
> >ANTIKERI LH Morocco 20/10/2006 391
> >ANTIKERI EA Morocco 31/10/2006 402
> >ANTIKERI EA Italy 8/12/2006 440
> >ANTIKERI EA Italy 8/12/2006 440
> >ANTIKERI EA Italy 30/12/2007 827
> >ANTIKERI EA Italy 30/12/2007 827
>
> >I had thought of using a means separation with proc GLM to build my
> >groups but each vessel is going but I figure there has to be better
> >way... Because essentially I want to set my LSD value to exactly 60....
> >Of course any of your thoughts on a better way of grouping is most
> >welcome
>
> >If you would like to read the previous data set into SAS you can use
> the
> >following code...
>
> >data ves;
> >informat date DDMMYY10.;
> >input entry $ vessel $ org $ dest $ date tdiff;
> >cards;
>
> >1 ANTIKERI EA Italy 24/09/2005 0
> >2 ANTIKERI EA Italy 13/12/2005 80
> >3 ANTIKERI EA Italy 13/12/2005 80
> >4 ANTIKERI EA Italy 14/12/2005 81
> >5 ANTIKERI LH Turkey 13/05/2006 231
> >6 ANTIKERI EA Italy 8/8/2006 318
> >7 ANTIKERI EA Italy 8/8/2006 318
> >8 ANTIKERI EA Italy 8/8/2006 318
> >9 ANTIKERI LH Morocco 19/10/2006 390
> >10 ANTIKERI LH Morocco 19/10/2006 390
> >11 ANTIKERI LH Morocco 20/10/2006 391
> >12 ANTIKERI LH Morocco 20/10/2006 391
> >13 ANTIKERI EA Morocco 31/10/2006 402
> >14 ANTIKERI EA Italy 8/12/2006 440
> >15 ANTIKERI EA Italy 8/12/2006 440
> >16 ANTIKERI EA Italy 30/12/2007 827
> >17 ANTIKERI EA Italy 30/12/2007 827
> >;
> >run;
>
> >Thank You,
>
> >Kevin Morgan- Hide quoted text -
>
> - Show quoted text -
|