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 (July 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 21 Jul 2004 17:08:08 -0400
Reply-To:   sashole@bellsouth.net
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Paul M. Dorfman" <sashole@BELLSOUTH.NET>
Organization:   Sashole of Florida
Subject:   Re: double dow
Comments:   To: Cool <cool_guy@oddpost.com>
In-Reply-To:   <10608670.1090442171464.JavaMail.www-data@c005>
Content-Type:   text/plain; charset="us-ascii"

Cool,

You appear to understand everything correctly, if a bit incompletely: For each input file named in a SET statement (as well as MERGE), SAS creates its own input stream. So, TTOTAL named in the first SET formes its own input source, while that named in the second SET forms an identical but independent source. As a result, when the first DoW has gone through a by-group reading from TTOTAL #1, the second DoW starts processing the same by-group from TTOTAL #2. Once you run it, you will see in the log that there will be two messages about reading N observations from file TTOTAL. The BY statement in both DoW-loops guarantees than the BY-groups read from both streams are synchronized (try commenting out the second BY and see what happens). They can also be synchronized by forcing the second loop to read exactly as many records from the second bucket as has just been read from the current BY-group in the first bucket:

Data one ; do _n_ = 1 by 1 until ( last.inst ) ; set ttotal ; by inst ; totfund = sum (totfund, fund, 0) ; end ; do _n_ = 1 to _n_ ; set ttotal ; output ; end ; Run ;

I have used this trick not so log ago on -L. I hope it makes things more clear.

Kind regards, ---------------- Paul M. Dorfman Jacksonville, FL ----------------

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Cool > Sent: Wednesday, July 21, 2004 4:36 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: double dow > > OK - Ive seen this a million times and even used it twice. > Only problem is that I don't fully understand (dangerous, I > know!!). I pulled the code below off of SAS-L: > > > Data one ; > do until ( last.inst ) ; > set ttotal ; > by inst ; > totfund = sum (totfund, fund, 0) ; > end ; > do until ( last.inst ) ; > set ttotal ; > by inst ; > output ; > end ; > Run ; > > > I know that this code essensially puts the sum of fund (by > inst) on each record. Trouble is, I don't understand how SAS > reads records and then goes back. I thought that every time > the "set" statement is called, SAS increments the record > pointer by one record (hence the first do until loop). > Question: On the second loop, how does SAS know to repeat the > same by group again? Can someone explain? > > Thanks, > Cool >


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