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 (May 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 23 May 2008 23:27:58 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Subject:      Re: loop through file to compare line above and line below?
Content-Type: text/plain; charset=ISO-8859-1

On Tue, 20 May 2008 05:10:41 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:

>Hmmm been a while since I work cattle but I dont think that will be much of a problem here. Still miss the good ol days. > >This should get you started: >Data CatList ; >Format DateTime DateTime20. ; >Input ID DateTime DateTime18. CowWeight CalfWeight ; >Cards ; >121212 01Jun2007:07:52:00 470 100 >121212 01Jul2007:11:53:00 470 100 >121212 01Jul2007:11:54:00 465 90 >199999 05Jul2007:10:22:00 448 90 >199999 05Jul2007:10:24:00 454 80 >199999 08Jul2007:02:21:00 454 90 >Run ; > > >Data Need ( Drop = LastCow LastCalf LastDateTime ) ; >Set CatList ; >By ID DateTime ; >Retain LastCow LastCalf LastDateTime ; > >If ( Not First.Id ) Then Do ; > If ( ( DateTime - LastDateTime ) Le 120 ) > And > ( ( CowWeight Ne LastCow ) Or ( CalfWeight Ne LastCalf ) ) > Then Output ; >End ; > >LastCow = CowWeight ; >LastCalf = CalfWeight ; >LastDateTime = DateTime ; > >Run ; > > >Notice I reworked your original data. Basically I modified it to to a form more suitable to a SAS solution.

Yes, just about every field had a problem.

DATE values were not stored in compliance with SAS date convention. If they looked right, it's because they were so far off (about 20,000 years) that they were out-of-range for the SAS date format.

TIME values were not stored in compliance with SAS time convention.

DATE and TIME need to be combined as a datetime in case any time comparisons straddle midnight.

The two weights should be handled as separate numerics.

All of these issues can be managed via SAS code, without editing the data lines at all.

DATA cat_list; infile cards dlm=' /'; informat cattle_id $6. date mmddyy8. time time5.; input cattle_id date time mom_weight baby_weight; time = dhms(date,0,0,time); drop date; format time datetime.; CARDS; 121212 07012007 7:52 470/100 121212 08012007 11:53 470/100 121212 08012007 11:54 465/90 199999 08052007 10:22 448/90 199999 08052007 10:24 454/80 199999 08082007 2:21 454/90 ;

> > >Toby Dunn > > >> Date: Mon, 19 May 2008 21:38:19 -0700 >> From: haleyjo@GMAIL.COM >> Subject: loop through file to compare line above and line below? >> To: SAS-L@LISTSERV.UGA.EDU >> >> We mark our cattle with tag ids for various reasons - here it is when >> they have a baby, and we weigh both mom and baby. The file looks like >> this: >> >> DATA cat_list; >> input cattle_id date time $ mom_baby_weight $; >> format date mmddyy8.; >> >> CARDS; >> 121212 07012007 7:52 470/100 >> 121212 08012007 11:53 470/100 >> 121212 08012007 11:54 465/90 >> 199999 08052007 10:22 448/90 >> 199999 08052007 10:24 454/80 >> 199999 08082007 2:21 454/90 >> run; >> >> How would I determine how many with the same cattle_id had a >> mom_baby_weight reading within 2 minutes of each other on the same >> date? And of those with two readings within 2 minutes -- how could I >> tell what percent had a mom_baby_weight ratio go lower on the 2nd >> reading (determined by either top vs top number or bottom vs bottom >> number -- 2nd reading lower on either number)? >> >> Thanks in advance. > >_________________________________________________________________ >Change the world with e-mail. Join the i�m Initiative from Microsoft. >http://im.live.com/Messenger/IM/Join/Default.aspx?source=EML_WL_ChangeWorld


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