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
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
retain _N 0;
if _N in (1,5,6,10) then output;
===== (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.
Videtis illam spirare libertatis auram
> so, you could say
> if mod(_N_,10) in (0,1,5,6)
> if mod (_N_,5) in (0,1)
> which is a bit simpler.
> On Wed, Feb 25, 2009 at 3:32 PM, Ben Powell <firstname.lastname@example.org>
>> Dear list
>> Complete mental block here - how do I get every 1st, 5th, 6th and
>> observation from a dataset, i.e. the outside observations in each
>> pair of a
>> group of 5?
>> Any comments much appreciated