Date: Thu, 11 Jul 2002 10:28:38 -0400
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: A datastep question...
Content-Type: text/plain; charset="iso-8859-1"
Dave,
I spent many years preaching as you did here, but let's make a test (SAS 8.2
under windows 98) and see. Here is the code
%let n = 1000 ;
%let x = 7 ;
data input ;
array id (&n) id1-id&n ( &n*0 ) ;
do obs = 1 to 10000 ;
if obs > 9000 then id3 = &X ;
output ;
end ;
run ;
DATA InputData ;
SET Input(KEEP=ID1 ID2 ID3 WHERE=(ID3=&X));
RUN;
DATA InputData(KEEP=ID1 ID2) ;
SET Input(WHERE=(ID3=&X));
RUN;
Results:
KEEP on KEEP on
X Input Output
- ----- ------
7 7.35 sec 6.37 sec
0 7.29 sec 6.36 sec
You cannot argue for your version of the code on the grounds of
inefficiency, however you might claim your code conveys the intent more
clearly and efficiency is not important.
IanWhitlock@westat.com
-----Original Message-----
From: dkb@CIX.COMPULINK.CO.UK [mailto:dkb@CIX.COMPULINK.CO.UK]
Sent: Thursday, July 11, 2002 4:08 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: A datastep question...
Jan,
Your suggestion is correct but it could be inefficient, because it will
read all the variables from DB.Input. Benjamen's code only reads the
variables he is interested in, so it would be better from a performance
point of view to combine his approach and yours, for instance:
DATA InputData;
SET DB.Input(KEEP=ID1 ID2 ID3 WHERE=(ID3=&X);
keep ID1 ID2;
RUN;
Kind regards,
Dave
Jan Padilla suggests:
> If you put the keep option on the output dataset, you don't need to
keep
> the variables used for subsetting.
>
> DATA InputData(KEEP=ID1 ID2);
> SET DB.Input(WHERE=(ID3=&X);
> RUN;
>
> On Wed, 10 Jul 2002 16:39:00 -0400, Witness <bmeyer67@CALVIN.EDU>
wrote:
>
> >Well, not necessarily a datastep, but...
> >
> >I have been starting to use WHERE clauses in set statements to limit
my
> >data instead of using the subsetting-IF. However, I still find that I
> >need to have the COLUMN that I am using in the WHERE clause to in
order
> >to run the step.
> >
> >Example:
> >
> >DATA InputData;
> > SET DB.Input(KEEP=ID1 ID2 ID3 WHERE=(ID3=&X);
> > RUN;
.