Let's say that I have a dataset with 2 columns: observation (from 1 to
n) and x (a continuous variable from 0 to 100).
I want to write the following algorith:
if x (obs=i) <20 and x ( obs = i-1) is > 20 then y = 1;
else y =0;
where y would be a new column with value 0 or 1, and "i" is a
particular observation.
In other words, for each row or observation, if x <20 and the previous
value for x (that is the value of x of the previous observation or
row) is > 20, then y would get a 1, otherwise y would be 0.
Thanks in advance!
|
|
0
|
|
|
|
Reply
|
nuria
|
8/26/2010 12:50:04 AM |
|
On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
> Let's say that I have a dataset with 2 columns: observation (from 1 to
> n) and x (a continuous variable from 0 to 100).
>
> I want to write the following algorith:
>
> if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> else y =3D0;
>
> where y would be a new column with value 0 or 1, and "i" is a
> particular observation.
>
> In other words, for each row or observation, if x <20 and the previous
> value for x (that is the value of x of the previous observation or
> row) is > 20, then y would get a 1, otherwise y would be 0.
>
> Thanks in advance!
if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
|
|
0
|
|
|
|
Reply
|
Ya
|
8/26/2010 12:59:54 AM
|
|
On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
> On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
>
>
>
>
> > Let's say that I have a dataset with 2 columns: observation (from 1 to
> > n) and x (a continuous variable from 0 to 100).
>
> > I want to write the following algorith:
>
> > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > else y =3D0;
>
> > where y would be a new column with value 0 or 1, and "i" is a
> > particular observation.
>
> > In other words, for each row or observation, if x <20 and the previous
> > value for x (that is the value of x of the previous observation or
> > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > Thanks in advance!
>
> if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
Or since SAS evaluates boolean expressions as 1 for true and 0 for
false you do not need the IF statement.
y =3D ( x<20 and lag(x) > 20 );
|
|
0
|
|
|
|
Reply
|
tom.abernathy (199)
|
8/26/2010 5:16:53 AM
|
|
On Aug 25, 10:16=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
>
>
>
> > On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > Let's say that I have a dataset with 2 columns: observation (from 1 t=
o
> > > n) and x (a continuous variable from 0 to 100).
>
> > > I want to write the following algorith:
>
> > > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > > else y =3D0;
>
> > > where y would be a new column with value 0 or 1, and "i" is a
> > > particular observation.
>
> > > In other words, for each row or observation, if x <20 and the previou=
s
> > > value for x (that is the value of x of the previous observation or
> > > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > > Thanks in advance!
>
> > if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
>
> Or since SAS evaluates boolean expressions as 1 for true and 0 for
> false you do not need the IF statement.
>
> y =3D ( x<20 and lag(x) > 20 );
That is great!
Lag is to refer to the previous observation, how do you refer to the
next one?
|
|
0
|
|
|
|
Reply
|
nchapinal (89)
|
8/26/2010 9:48:22 PM
|
|
Getting the NEXT observation is not really part of the language.
You can trick it.
data new;
merge old old(firstobs=3D2 keep=3Dx rename=3D(x=3Dlead_x) );
y =3D max(x,lag(x),lead_x);
run;
On Aug 26, 5:48=A0pm, nuria <nchapi...@yahoo.com> wrote:
> On Aug 25, 10:16=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
>
>
>
>
> > On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
>
> > > On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > > Let's say that I have a dataset with 2 columns: observation (from 1=
to
> > > > n) and x (a continuous variable from 0 to 100).
>
> > > > I want to write the following algorith:
>
> > > > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > > > else y =3D0;
>
> > > > where y would be a new column with value 0 or 1, and "i" is a
> > > > particular observation.
>
> > > > In other words, for each row or observation, if x <20 and the previ=
ous
> > > > value for x (that is the value of x of the previous observation or
> > > > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > > > Thanks in advance!
>
> > > if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
>
> > Or since SAS evaluates boolean expressions as 1 for true and 0 for
> > false you do not need the IF statement.
>
> > y =3D ( x<20 and lag(x) > 20 );
>
> That is great!
>
> Lag is to refer to the previous observation, how do you refer to the
> next one?
|
|
0
|
|
|
|
Reply
|
tom.abernathy (199)
|
8/26/2010 11:03:19 PM
|
|
Or, take a look at:
http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back
HTH,
Art
-----------
On Aug 26, 7:03=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> Getting the NEXT observation is not really part of the language.
> You can trick it.
>
> data new;
> =A0 =A0merge old old(firstobs=3D2 keep=3Dx rename=3D(x=3Dlead_x) );
> =A0 =A0y =3D max(x,lag(x),lead_x);
> run;
>
> On Aug 26, 5:48=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
>
>
> > On Aug 25, 10:16=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
> > > On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
>
> > > > On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > > > Let's say that I have a dataset with 2 columns: observation (from=
1 to
> > > > > n) and x (a continuous variable from 0 to 100).
>
> > > > > I want to write the following algorith:
>
> > > > > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > > > > else y =3D0;
>
> > > > > where y would be a new column with value 0 or 1, and "i" is a
> > > > > particular observation.
>
> > > > > In other words, for each row or observation, if x <20 and the pre=
vious
> > > > > value for x (that is the value of x of the previous observation o=
r
> > > > > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > > > > Thanks in advance!
>
> > > > if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
>
> > > Or since SAS evaluates boolean expressions as 1 for true and 0 for
> > > false you do not need the IF statement.
>
> > > y =3D ( x<20 and lag(x) > 20 );
>
> > That is great!
>
> > Lag is to refer to the previous observation, how do you refer to the
> > next one?- Hide quoted text -
>
> - Show quoted text -
|
|
0
|
|
|
|
Reply
|
art297 (4237)
|
8/26/2010 11:33:29 PM
|
|
On Aug 26, 4:33=A0pm, Arthur Tabachneck <art...@netscape.net> wrote:
> Or, take a look at:http://www.sascommunity.org/wiki/Look-Ahead_and_Look-B=
ack
>
> HTH,
> Art
> -----------
> On Aug 26, 7:03=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
> > Getting the NEXT observation is not really part of the language.
> > You can trick it.
>
> > data new;
> > =A0 =A0merge old old(firstobs=3D2 keep=3Dx rename=3D(x=3Dlead_x) );
> > =A0 =A0y =3D max(x,lag(x),lead_x);
> > run;
>
> > On Aug 26, 5:48=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > On Aug 25, 10:16=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
> > > > On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
>
> > > > > On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > > > > Let's say that I have a dataset with 2 columns: observation (fr=
om 1 to
> > > > > > n) and x (a continuous variable from 0 to 100).
>
> > > > > > I want to write the following algorith:
>
> > > > > > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > > > > > else y =3D0;
>
> > > > > > where y would be a new column with value 0 or 1, and "i" is a
> > > > > > particular observation.
>
> > > > > > In other words, for each row or observation, if x <20 and the p=
revious
> > > > > > value for x (that is the value of x of the previous observation=
or
> > > > > > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > > > > > Thanks in advance!
>
> > > > > if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
>
> > > > Or since SAS evaluates boolean expressions as 1 for true and 0 for
> > > > false you do not need the IF statement.
>
> > > > y =3D ( x<20 and lag(x) > 20 );
>
> > > That is great!
>
> > > Lag is to refer to the previous observation, how do you refer to the
> > > next one?- Hide quoted text -
>
> > - Show quoted text -
Thanks for the link!
I was wondering if there was the an equivalent function to "lag" to
refer the next observation. I guess not, otherwise I would have found
it by now... however, it is surprising!
Does anyone know if such a function exists:
|
|
0
|
|
|
|
Reply
|
nchapinal (89)
|
8/27/2010 5:36:24 PM
|
|
On Aug 27, 1:36=A0pm, nuria <nchapi...@yahoo.com> wrote:
> On Aug 26, 4:33=A0pm, Arthur Tabachneck <art...@netscape.net> wrote:
>
>
>
>
>
> > Or, take a look at:http://www.sascommunity.org/wiki/Look-Ahead_and_Look=
-Back
>
> > HTH,
> > Art
> > -----------
> > On Aug 26, 7:03=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
> > > Getting the NEXT observation is not really part of the language.
> > > You can trick it.
>
> > > data new;
> > > =A0 =A0merge old old(firstobs=3D2 keep=3Dx rename=3D(x=3Dlead_x) );
> > > =A0 =A0y =3D max(x,lag(x),lead_x);
> > > run;
>
> > > On Aug 26, 5:48=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > > On Aug 25, 10:16=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrot=
e:
>
> > > > > On Aug 25, 8:59=A0pm, Ya <huang8...@gmail.com> wrote:
>
> > > > > > On Aug 25, 5:50=A0pm, nuria <nchapi...@yahoo.com> wrote:
>
> > > > > > > Let's say that I have a dataset with 2 columns: observation (=
from 1 to
> > > > > > > n) and x (a continuous variable from 0 to 100).
>
> > > > > > > I want to write the following algorith:
>
> > > > > > > if x (obs=3Di) <20 and x ( obs =3D i-1) is > 20 then y =3D 1;
> > > > > > > else y =3D0;
>
> > > > > > > where y would be a new column with value 0 or 1, and "i" is a
> > > > > > > particular observation.
>
> > > > > > > In other words, for each row or observation, if x <20 and the=
previous
> > > > > > > value for x (that is the value of x of the previous observati=
on or
> > > > > > > row) is > 20, then y would get a 1, otherwise y would be 0.
>
> > > > > > > Thanks in advance!
>
> > > > > > if x < 20 and lag(x) > 20 then y=3D1; else y=3D0;
>
> > > > > Or since SAS evaluates boolean expressions as 1 for true and 0 fo=
r
> > > > > false you do not need the IF statement.
>
> > > > > y =3D ( x<20 and lag(x) > 20 );
>
> > > > That is great!
>
> > > > Lag is to refer to the previous observation, how do you refer to th=
e
> > > > next one?- Hide quoted text -
>
> > > - Show quoted text -
>
> Thanks for the link!
>
> I was wondering if there was the an equivalent function to "lag" to
> refer the next observation. I guess not, otherwise I would have found
> it by now... however, it is surprising!
> Does anyone know if such a function exists:
There is not a function, that is why the other solutions have been
created.
For most real world problems it is not needed.
Perhaps if you describe your problem someone can suggest another way
to store the data that will make the calculations easier.
|
|
0
|
|
|
|
Reply
|
tom.abernathy (199)
|
8/27/2010 11:56:08 PM
|
|
|
7 Replies
202 Views
(page loaded in 0.107 seconds)
Similiar Articles: a*star algorithm in 3D - comp.soft-sys.matlabalgorithms: reference to the previous observation - comp.soft-sys ... > > I want to write the following algorith: > > if x (obs=3Di) <20 and x ( obs =3D ... Clock selection? - comp.protocols.time.ntpIt is at least encouraging to know that the observation is not ... time.ntp It has no choice but to believe its reference clock so the filters and selection algorithms are ... Practical Bit-loading (ADSL/VDSL): fundamental problem - comp.dsp ...Fact#1) Bit-loading algorithms assume that the ... and every 2 bits will need 4 time the previous ... Reference: VDSL2 standard .....section 10.3.4 ( Link ... w32time - comp.protocols.time.ntp> > -- > RPM Thanks for your observations, Ryan. The earlier ... ISG first step - comp.dcom.sys.cisco w32time - comp.protocols.time.ntp > replacing W32time with reference ... Single best NTP status indicator of clock accuracy? - comp ...... the approach used by chrony-- doing a linear fit to the the past ... bc637PCI-U Reference Clock Driver - comp.protocols.time.ntp ... Single best NTP status indicator of ... Question about 2008 leap second - comp.protocols.time.ntp ...I read that, during the previous leap second, in the ... to which the client had selected as the primary reference. ... NTP Leap Seconds Indicator - comp.protocols.time.ntp I ... 52-week high rolling window -- HELP!!!!! - comp.soft-sys.sas ...... create a SQL query, which finds the previous ... an additional column containing the past 52-week high for each observation. ... I find also this quick reference very helpful ... NTP over redundant peer links, undetected loops - comp.protocols ...The stratum of both references goes up poll by poll, until ... As soon as you get significantly past that sqrt(N ... redundant peer links, undetected loops - comp.protocols ... Synchronizing NTP in WAN and LAN - comp.protocols.time.ntp ...... has been my main environment for the past 15 ... and by one for each layer ... GPS reference, and a "good" LAN, you can synchronize two ... and LAN - comp.protocols.time.ntp ... SAS datasets keeping first 2 obs for each ref number - comp.soft ...Exceeded observation length - comp.soft-sys.sas SAS ... with rotation of view so that it will give reference ... ... Meinberg NTP Software--Time Accuracy - comp.protocols ... algorithms: reference to the previous observation - sassas, algorithms: reference to the previous observation . comp.soft-sys.sas - The SAS statistics package. AlgorithmsIt is based on the observation that blocks which have ... policy combining both LRU and LFU algorithms in order ... the reference density observed during the past references. 7/23/2012 4:19:49 AM
|