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 (June 2002, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 11 Jun 2002 16:24:28 -0400
Reply-To:   "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Subject:   Re: Elementary SAS Merge
Comments:   To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Content-Type:   text/plain; charset=iso-8859-1

> Here's my concise definition: The LAG function returns the value > passed as an argument in the previous call to the same occurrence of > that same LAG function If this is the first time it has been > called, it returns a missing value.

Jack,

Maybe a visual FIFO picture could be better memorized than a definition: The value of an argument inserted in the back of the queue "displaces" the rest of the items in the queue up by 1 position, ejecting the value in the front of the queue as a result.

%let nlag = 4 ;

data _null_ ; array q ( 99 ) _temporary_ ; front = hbound (q) ; link showqueue ; do arg = 1 to 9, . ; return = lag&nlag (arg) ; front +- 1 ; q (front - &nlag + 1) = arg ; link showqueue ; end ; stop ; showqueue: put arg 3. ' ---> ' @ ; do pos = front - &nlag + 1 to front ; put q (pos) 3. @ ; end ; put +2 ' ---> ' return 3. / @12 10*'-' ; run ;

. ---> . . . . ---> . ---------- 1 ---> 1 . . . ---> . ---------- 2 ---> 2 1 . . ---> . ---------- 3 ---> 3 2 1 . ---> . ---------- 4 ---> 4 3 2 1 ---> . ---------- 5 ---> 5 4 3 2 ---> 1 ---------- 6 ---> 6 5 4 3 ---> 2 ---------- 7 ---> 7 6 5 4 ---> 3 ---------- 8 ---> 8 7 6 5 ---> 4 ---------- 9 ---> 9 8 7 6 ---> 5 ---------- . ---> . 9 8 7 ---> 6 ----------

From the utilitarian programmatic standpoint, the difference between a queue and array of the same size is thus: The queue provides an efficient internal mechanism of moving all the elements up by one position via a single O(1) isntruction, while providing an O(1) access only to the front item. The array provides an O(1) access to any item, but moving all of the array items up by 1 takes O(n) time.

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

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.


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