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 (April 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 5 Apr 2002 20:35:46 +0100
Reply-To:     Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Organization: Crawford Software Consultancy Limited
Subject:      Re: dynamics~~DOW
Content-Type: text/plain;charset=iso-8859-1

Have to be impressed ! >time to explain, below is a propaedeutic comment

propaedeutic / / adj. & n. adj. serving as an introduction to higher study; introductory. n. (esp. in pl.) preliminary learning; a propaedeutic subject, study, etc. propaedeutical adj. [pro-2 + Greek paideutikos ‘of teaching’, suggested by Greek propaideuo ‘teach beforehand’]

Dorfman, Paul <Paul.Dorfman@BCBSFL.COM> writes >Howard, > >Two points. First, I think the "new-fangled" excerpt you was written by >David Cassell. Second, I think that the scope and applicability of DOW is >wider than Do...Until(Last.ID). The latter is just the form I originally saw >in one of Ian's posts, and the most frequently used one. Instead of spending >time to explain, below is a propaedeutic comment that I %include in a >program where I use DoW and have a suspicion that the program might be >inherited, in accordance with my slothful custom of reusing old stuff: > >---------------------------------------- >This program may contain one or more constructs similar to the following: > >Data <...Data Set Names...> ; > <...Stuff Executed Before Break-Event... > ; > Do <...Cnt-Var = From-Var By Step-Var...> Until ( Break-Event ) ; > Set A ; > <...Stuff Executed For Each In-Record...> ; > End ; > <...Stuff Executed After Break-Event... > ; >Run ; > ><The code between angle brackets is, generally speaking, optional.> We call >the structure the DoW-loop or simply DoW, where W stands for Ian Whitlock. > >The intent of organizing such a structure is to achieve a logical isolation >of instructions executed between two successive break-events from actions >performed before and after a break-event, in a programmatically-natural >manner. In most (but not all) situations, the input data set is grouped >and/or sorted, and the break-event occurs when the last record in a by-group >has been processed. In such a case, DoW logically separates actions >performed (1) before the first record in a by-group has been read, (2) for >each record in the group, and (3) after the last record in the group has >been read. > >EXAMPLE: Input file A is sorted by ID. This step multiplies and summarizes >all VAR values within each ID-group, counts the number of all and >non-missing records in each group, finds the group average, and writes 1 >record with COUNT, SUM, MEAN and PROD to file B after each by-group: > >Data B ( Keep = Id Prod Sum Count Mean) ; > Prod = 1 ; > Do Count = 1 By 1 Until ( Last.Id ) ; > Set A ; > By Id ; > If Var <= .Z Then Continue ; > Mcount = Sum (Mcount, 1) ; > Prod = Prod * Var ; > Sum = Sum (Sum, Var) ; > End ; > Mean = Sum / Mcount ; >Run ; > >How it works (1, 2, 3 denote stuff performed before, between, and after >break-event<s>): (1) PROD and COUNT are set to 1, and the non-retained SUM, >MEAN, and MCOUNT are set to missing by default (control is at the top of the >Data step). (2) DOW-loop starts to iterate, reading the next record from A >at the top of every iteration. While it iterates, control never leaves the >Do-End boundaries. If VAR is missing, CONTINUE passes control straight to >the bottom of the loop, otherwise MCOUNT, PROD and SUM are computed. After >the last record in the group has been processed, the loop stops. At this >point, PROD, COUNT, SUM, and MEAN contain the group aggregate values. (3) >Control is transferred to the statement following the loop. MEAN is >computed, and control is passed to the bottom of the step, where the >implicit OUTPUT writes the record to B. (4) Control is passed to the top of >the step, the variables are re-initialized, and the next group is processed. > > >Note: Contrary to the common practice, the accumulation variables need NOT >be retained. Because DoW passes control to the top of the Data step only >before the first record in a by-group is to be read, this is the only point >where non-retained variables are reset to missing, and it is exactly where >this action is required. >------------------------------------------------------ > >Kind regards, >================== >Paul M. Dorfman >Jacksonville, FL >================== > > >> -----Original Message----- >> From: Howard_Schreier@ITA.DOC.GOV [mailto:Howard_Schreier@ITA.DOC.GOV] >> Sent: Friday, April 05, 2002 11:51 AM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: Re: dynamics~~DOW >> >> >> This is just a comment on terminology. >> >> The DOW loop is a particular kind of DO ... UNTIL. The exit >> condition is of >> the form LAST.SOMETHING and the SET and BY statements are >> inside the loop. >> >> On Thu, 31 Jan 2002 12:41:10 -0500, Dorfman, Paul >> <Paul.Dorfman@BCBSFL.COM> >> wrote: >> >> >> The new-fangled way is to use the Whitlock do-loop, like this: >> >> >> >> data new; >> >> do count=1 by 1 until (last.ident); >> >> set old; >> >> by ident; >> >> output; >> >> end; >> >> run; >> > >> >DOW-loop sounds like a good name for it, don't you think ? :-) >> >> >> On Thu, 4 Apr 2002 15:15:18 -0500, kviel <kviel@GMCF.ORG> wrote: >> >> >I would like to modify my code to my original response. The >> DOW can be used >> >for the raw data also. The variable END in my last post was >> an artefact of >> >my testing of the the data step process. >> > >> >data one (keep=var2-var4); >> >infile datalines eof=eof; >> >array v(3) var2-var4; >> >do i=1 by 1 until (i=3); >> > input var1; >> > v(i)=var1; >> >end; >> >output; >> >eof: output; >> >datalines; >> [snip] >> >> > > >Blue Cross Blue Shield of Florida, Inc., and its subsidiary and >affiliate companies are not responsible for errors or omissions in this e-mail >message. Any personal comments made in this e-mail do not reflect the views of >Blue Cross Blue Shield of Florida, Inc.

-- Peter Crawford


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