Date: Thu, 4 Dec 2003 14:22:49 +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: Newbie Question How to Delete Variable from SAS Dataset
In-Reply-To: <E1ARtrl-0008JT-00@coumxnn02.netbenefit.co.uk>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 05:27 04/12/03 +0100, toby989 wrote:
>Your suggestions create a new dataset (b) and copy only selected ones into
>the new dataset from the old one (a). I would not want to do this, because
>then I would have to delete a and rename b to a. I really only want to
>delete one variable from a. If thats the only possibility SAS offers to do
>it, then I think it doesn't allow for good programming practice, since
>memory is still used up by the old dataset ...
Toby, if you don't want to retain the original dataset (a), then you can
over-write it with the new one:
data a (drop = z) ;
set a ;
run ;
>.... and processor time/overhead is required by the whole copying process.
True, but if there were provision for simply deleting a variable/'column'
'in situ', without re-writing ('copying') the original, then it would have
an inflated size, again using up memory/storage space unnecessarily.
It's also worth considering whether, if it's not a 'permanent' requirement
(in which case it makes sense to re-write the smaller dataset), whether you
actually need to delete the variable - since you always have the option to
drop any un-needed variables in any DATA or PROC step; if you do that with
a dataset option on the incoming dataset, the unwanted variables won't even
be read into the step, for example:
data c ;
set a (drop = z) ;
.....
OR
proc whatever data = a (drop = z) ;
......
An alternative approach would be to create a dataset view, for example:
data b (drop = z) / view=b ;
set (a) ;
In this case, dataset (b) does not actually exist, and therefore does not
occupy any memory/storage space; it is a 'virtual dataset' which will be
created from (a), by omission of variable z, each time 'dataset b' is
referenced.
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
----------------------------------------------------------------