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 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 17 Jun 1996 16:15:48 -0700
Reply-To:   Bruce Rogers <gxx18300@GGR.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Bruce Rogers <gxx18300@GGR.CO.UK>
Organization:   Glaxo Wellcome
Subject:   Re: Retain statement
Comments:   To: Gaylen Fraley <gfraley@primenet.com>

> > > Bruce Rogers wrote: > > > > > > > > No, It makes no difference where you put the RETAIN statement. It is > > > > non-procedural, retaining values of any specified variables, whatever > > > > position it is placed in. > > > > <snipped> > > > > > > > > This is NOT correct. The placement of the RETAIN statement IS important. The > > > following example illustrates this: > > > > > > data ONE; > > > do i = 1 to 10; > > > output; > > > end; > > > run; > > > > > > data TWO; > > > retain _all_; > > > set ONE; > > > if I = 1 then X = 1; > > > run; > > > > > > /* According to your statement, all 10 records should retain the value of X=1. > > */ > > > /* You will discover that X=1 is only in the first record. If, however, you > > */ > > > /* move the RETAIN staement AFTER the IF i=1 statement, THEN all 10 records > > will */ > > > /* retain the value for X. */ > > > > > > > Gaylen, > > > > Your results are correct, but your conclusion is not. The reason your code does > > not retain > > the value of X is not the position of the RETAIN statement, but the fact that > > you have used > > _ALL_ instead of naming the variables required. The variable X is not known at > > the point you > > specify _ALL_ (over-simplifying things a bit, I know), so it is not retained at > > all. If you > > replace the _ALL_ with the variable names I and X, the predicted results (i.e. X > > always = 1 ) > > will be given. > > > > > > Bruce > > > > p.s. Don't be so quick to knock other people's ideas. :-) > > > > Bruce, > > I am not "knocking other ideas". I have simply stated that RETAIN is placement important IF > you use an IMPLICIT RETAIN, as in RETAIN _ALL_ or RETAIN (w/o any EXPLICIT variables). > My conclusion is based on that fact and that fact alone. The placement of an EXPLICIT > RETAIN statement is NOT important. An IMPLICIT RETAIN is important. > >

OK, if you use the implicit retain the position relative to the position of other elements of code, can be relevant, although I don't remember you mentioning this on the earlier postings. The point was really that any retained variable is treated the same, wherever the RETAIN statement is placed. Using the implicit form, as you have, merely excludes some variables from the retained list.

Personally speaking, I'd never use the implicit form anyway, as I like my programs to be easy to read ( by myself or anyone else) and feel that explicitly retaining variables (with suitable comments, of course) makes them far more readable.

Bruce.

p.s. Haven't you ever seen smilies before? :-) :o)


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