Date: Mon, 22 Apr 1996 23:50:48 +0100
Reply-To: John Whittington <johnw@MAG-NET.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: John Whittington <johnw@MAG-NET.CO.UK>
Subject: Re: PUT creates variable?
On Mon, 22 Apr 1996, "Robert M. Hamer" <hamer@GANDALF.RUTGERS.EDU> wrote (in
part):
>The reason is that SAS was designed so that variables
>never _need_ to be explicitly declared, in order to
>be added to the PDV.
>
>The design criteria included a goal that SAS should
>attempt to use intelligent defaults where possible.
>
>During the compile phase of a data step, the SAS compiler
>does the following things when encountering a variable
>for the first time:
>
> [detailed description of variable 'initialisation' omitted ]
My goodness, I never expected that my little comment was going to generate
so many, and so detailed, responses (there have been many private ones).
I do understand the benefits of the behaviour described by Robert, and
others, but no-one has yet actually addressed the specific point that I was
trying to address ....
If a variable is not in a dataset which is SET and is not in an INPUT
statement, then if its ONLY occurrence is in:
a PUT statement
OR on the right hand side of an assignment statement
OR in a LABEL statement
OR in a format statement .... etc.
.. then, my simple mind reckons that:
(a) .... this variable can NEVER have a non-missing value
(b) .... this inevitably occurs as a result of a coding error (or,
at the least, redundant code)
.. which leads me still to ask what benefits can ever derive from such
variables being included in the PDV and output dataset. If one wants an
'all missing' variable, then one can easily code it explicitly - and it
would surely be bad practice to create such a variable by any of these
'devious' methods.
If the compiler encounters a variable in ANY situation in which it could
(but not necessarily does) acquire a non-mising value, then I can fully
understand the benefits of that variable being automatically included in the
PDV, with whatever explicit or default attributes are appropriate. That
includes situations in which the variiable *may* never aquire a value (e.g.
when it is assigned a value in a data-conditional statement) and also
situations in which the programmer has implicitly 'requested initialisation'
(even if the variable is never assigned a value) in a RETAIN, LENGTH or
ATTRIB statement. However, I still do not see what is gained by
automatically placing 'never could have a value' variables in the PDV -
simply because the complier 'found the variable somewhere' in code! My
suspicion is that we are just seeing expediency - i.e. it was easier to make
SAS 'initialise' ANY variable it found ANYWHERE than it would be for the
compiler to have to 'think about' whether initialisation was appropriate!
... maybe I'm just dim, but I'm still waiting for someone to claim the
hypothetical 'free lunch' for finding a value of benefit of this functionality!
John
-----------------------------------------------------------
Dr John Whittington, Voice: +44 1296 730225
Mediscience Services Fax: +44 1296 738893
Twyford Manor, Twyford, E-mail: johnw@mag-net.co.uk
Buckingham MK18 4EL, UK CompuServe: 100517,3677
-----------------------------------------------------------