Date: Fri, 5 Jan 2001 14:06:51 -0500
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: do loop
Content-Type: text/plain; charset="iso-8859-1"
Yann,
You wanted
> i would like to get, for each observation, the number of others so that
the
> value of cli is the same and the difference between the two values of tps
is
> < c.
I would take a simple approach reading the file twice.
data w ; input cli tps tpsmax ; cards ;
1 2 45
1 8 45
1 21 45
1 45 45
4 2 12
4 5 12
4 7 12
4 8 12
4 12 12
;
%let c = 8 ;
data q ( drop = i m ) ;
array temp (1000) _temporary_ ;
i = 0 ;
do until ( last.cli ) ;
set w ;
by cli ;
i + 1 ;
temp(i) = tps ;
end ;
m = i ;
do until ( last.cli ) ;
set w ;
by cli ;
cnt = -1 ;
do i = 1 to m ;
if abs ( tps - temp(i) ) < &c then cnt + 1 ;
end ;
output ;
end ;
run ;
The line
> executing a %do loop from 1 to tpsmax doing
is the killer. TPSMAX is a data value known only during execution
while %DO will generate code at compile time, hence the plan as
stated cannot work.
Ian Whitlock <whitloi1@westat.com>
-----Original Message-----
From: ANDRIEUX Yann-Vai [mailto:yv.andrieux@COFINOGA.FR]
Sent: Friday, January 05, 2001 12:30 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: do loop
Dear SAS-Lers,
here is a problem I came across:
having a set
cli tps tpsmax
1 2 45
1 8 45
1 21 45
1 45 45
4 2 12
4 5 12
4 7 12
4 8 12
4 12 12
i would like to get, for each observation, the number of others so that the
value of cli is the same and the difference between the two values of tps is
< c.
the data being sorted by cli and tps, i thought setting number=0 and
executing a %do loop from 1 to tpsmax doing
number = number + (cli=lag&i(cli))*(tps-lag&i(cli)<c) ;
would do the job, but I always get the syntax wrong.
I need some help to have it work.
Thanks in advance
yann