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 (August 2001, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 30 Aug 2001 12:18:55 -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: Automatically RETAINed ??
Comments: To: Peetie Wheatstraw <peetie_wheatstraw@HOTMAIL.COM>
Content-Type: text/plain; charset=iso-8859-1

> So variables read with a SET are automatically retained. Right?

Yes.

> Now consider the following (NT 8.0) log: > > 135 data a; > 136 id=1; > 137 x1=1; > 138 x2=4; > 139 run; > 140 data b; > 141 id=1; > 142 x=3; > 143 data c; > 144 *retain; > 145 set a b; > 146 by id; > 147 put _all_; > 148 if (x1<=x<=x2); > 149 run; > > id=1 x1=1 x2=4 x=. FIRST.id=1 LAST.id=0 _ERROR_=0 _N_=1 > id=1 x1=. x2=. x=3 FIRST.id=0 LAST.id=1 _ERROR_=0 _N_=2 > NOTE: There were 1 observations read from the dataset WORK.A. > NOTE: There were 1 observations read from the dataset WORK.B. > NOTE: The data set WORK.C has 0 observations and 4 variables. > > As you can see, 'data c' iterated twice. It was intended > that the values of x1 and x2 from the first iteration > be available in the second iteration. But they were > not.

Yes, they were.

>I don't understand why. Please note that I get the same result if I uncomment > the retain statement.

Because the values of x1 and x2 coming from B are missing values, and they are missing NOT because they x1 and x2 were reset at the top of the step (they were not), but because B does not have them at all. Logically, SAS sets them to missing, and you are reading the interleaved file as if you were reading a file created as

data x ; id = 1 ; x1 = 1 ; x2 = 4 ; output ; x1 = . ; x2 = . ; output ; run ;

So, in the second iteration, the missing values simply overwrite x1=1 and x2=4 in memory.

> No doubt I'm missing some important facts re the data step > in interpreting the doc and/or composing the code. > Where did I go wrong? :-)

Nothing, actually! You simply expected unexpected.

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