Date: Wed, 25 Feb 2009 20:41:40 -0800
Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject: Re: 1st, 5th, 6th and 10th observations
In-Reply-To: <b7a7fa630902251342v6ffacb31y89dea0ab1a8d67fb@mail.gmail.com>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
On Feb 25, 2009, at 1:42 pm, Joe Matise wrote:
> _N_ is the observation number
Not exactly. _N_ is the number of the iteration through the data
step. If you use explicit looping, you can read and write a million
observations without _N_ every being anything but 1.
Ron used the code
=====
DATA Modulo_5;
retain _N 0;
do until(EndoFile);
_N+ +1;
if _N in (1,5,6,10) then output;
end;
stop;
===== (he omittted the RUN; at the end)
_N_ is 1 the whole time. He could have reused the variable _N_
instead of creating his own _N, a technique that Paul Dorfman often
uses. I'm not sure why he coded "+N + +1" instead of "_N + 1" or "_N
= _N + 1", or why he used a retain statement. He may have meant to
reset the counter so more than the first two pairs would be written
out, but the spec wasn't clear on that.
The advantage of Ron's method is that it can be much faster than using
the implicit data step loop.
--
Jack Hamilton
jfh@alumni.stanford.org
Videtis illam spirare libertatis auram
>
>
> so, you could say
> if mod(_N_,10) in (0,1,5,6)
>
> or
> if mod (_N_,5) in (0,1)
> which is a bit simpler.
>
> -Joe
>
> On Wed, Feb 25, 2009 at 3:32 PM, Ben Powell <ben.powell@cla.co.uk>
> wrote:
>
>> Dear list
>>
>> Complete mental block here - how do I get every 1st, 5th, 6th and
>> 10th
>> observation from a dataset, i.e. the outside observations in each
>> pair of a
>> group of 5?
>>
>> Any comments much appreciated
>>
>> Rgds
>>
|