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:   Fri, 31 Aug 2001 15:09:14 -0600
Reply-To:   Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject:   Re: Testing for empty file.
Comments:   To: Paul.Dorfman@bcbsfl.com
Content-Type:   text/plain; charset=us-ascii

You're correct about the user's ability to set _N_ to any value; I knew about that, but saying "SAS sets" clearly wasn't sufficient to indicate that my comments hold only if the user doesn't set explicitly _N_.

I hadn't thought about the existence of an internal counter variable, but you're right, SAS must do something like that internally, and the documentation is incorrect.

-- JackHamilton@FirstHealth.com Development Manager, Technical Group METRICS Department, First Health West Sacramento, California USA

>>> "Dorfman, Paul" <Paul.Dorfman@bcbsfl.com> 08/31/2001 1:49 PM >>> > SAS will never set _N_ to blank;

Quite true; SAS never sets it to missing, either. Of course, a user can set _N_ to anything, even a real character blank:

42 data _null_ ; 43 length b $8. ; 44 a = addr(_n_); 45 call poke (b, a, 8) ; 46 put _n_= ; 47 run ;

_N_=0.2509803922

The result, of course, is somewhat fancy...

>It will always be an integer >= 1.

Which is true as well, but *only* if tested *immediately* after the DATA statement. In any subsequent statements, _n_ can be user-set to anything, without any effect whatsoever upon its value at the top of the step, when and if control is transferred there again. Which means that the statement from the SAS manual you are quoting elsewhere in the thread,

Each time the DATA step loops past the DATA statement, the variable _N_ is incremented by 1.

is simply inaccurate, to put it mildly. If it were true, the following step:

data _null_ ; put _n_ @; set a (obs = 2) ; _n_ +- 1 ; run ;

would keep printing 1. In reality, it prints 1 2 3. The only explanation to this is that SAS could not care less how badly _n_ might be screwed up between the step boundaries, because he keeps the iteration count in a separate, internal variable, let's call it _INTN_, to which users - and for a good reason, too - have no access. *This* variable is incremented, indeed; but _n_ simply gets rewritten at the top of the step when the current value of _INTN_ is *moved* to _N_:

data .... ; _intn_ ++ 1 ; *first instruction we do not see; _n_ = _intn_ ; *second instruction we do not see; put _n_= ; *it appears as if _n_ were incremented; ... <more stuff> ; *here do with _n_ anything you want ; run ;

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