Date: Fri, 18 Feb 2000 07:14:18 +0000
Reply-To: John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject: Re: re-order variables
In-Reply-To: <200002172151.VAA05940@vicar.netnames.net>
Content-Type: text/plain; charset="us-ascii"
At 16:50 17/02/00 -0500, Lary Jones wrote (in part):
>A. DATA step option DATA Test2 (KEEP Mailname series);
> This specifies what is included in the output of the data step.
> Has no effect until an OUTPUT statement is encountered or is
> implied by the end of the data step.
I agree.
>B. SET statement option SET Test (KEEP Mailname series);
> This specifies which variables are brought into SAS (the PDV,
> or data vector) for processing in the DATA step. I believe that
> this form *will* affect variable order.
I don't think so. The code:
data test ;
a = 1 ; b = 2 ; c = 3 ; d = 4 ;
run ;
data try ;
set test (keep = d c b) ;
run ;
proc print data = try ; run ;
... produces output:
OBS B C D
1 2 3 4
... with no change in variable order.
>C. An independent statement KEEP mailname series;
> This specifies which variables will be available in the statements
> which follow the KEEP statement *after* all the variables have been
> loaded in the PDV.
Again, if I understand what Lary is saying here, I disagree. As far as I
am concerned, an 'independent KEEP statement' has the same effect as (A)
above - i.e. a KEEP dataset option on the output dataset. A KEEP statement
certainly does not make ann 'non-KEEPed' variables unavialable to
subsequent statements in the DAT step, in the manner that Lary implied:
7551 data test ;
7552 a = 1 ; b = 2 ; c = 3 ; d = 4 ;
7553 keep a b ;
7554 e = c + d ;
7555 put e = ;
7556 run ;
E=7
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: The DATA statement used 0.16 seconds.
>Corrections and alternate viewpoints are welcome ;-)
See above!! In essence, I don't believe that a KEEP statement can ever
influence variable ordering in the PDV. Incidentally:
7597 data test ;
7598 a = 1 ; b = 2 ; c = 3 ; d = 4 ;
7599 keep a b c d e ;
7600 run ;
WARNING: The variable E in the DROP, KEEP, or RENAME list has never been
referenced.
NOTE: The data set WORK.TEST has 1 observations and 4 variables.
NOTE: The DATA statement used 0.16 seconds.
... illustrating that KEEP does not create variables (only 4 variables in
the output dataset) - as others have pointed out, it couldn't, really,
since the compiler has no idea whther it is a numeric or character
variable, nor what its length is.
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------