f



getting upper and lower values from a reference value

Hi,

data m;
input volume ;
cards;
0.1234
0.2345
0.3435
0.4567
0.498
0.5345
0.6768
;
run;

i need to get  upper and lower values(considering 0.5 as my reference
point) which are nearst to .5 value

from the above example data the final result i have to get is 0.498(as
upper value) and 0.5345(as lower value)
because 0.5(imaginary reference value) lies in between these two
values.

Thanks in advance.
0
11/1/2011 2:59:52 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

2 Replies
427 Views

Similar Articles

[PageSpeed] 6

On Nov 1, 10:59=A0pm, mahi <mehetrey.mahen...@gmail.com> wrote:
> Hi,
>
> data m;
> input volume ;
> cards;
> 0.1234
> 0.2345
> 0.3435
> 0.4567
> 0.498
> 0.5345
> 0.6768
> ;
> run;
>
> i need to get =A0upper and lower values(considering 0.5 as my reference
> point) which are nearst to .5 value
>
> from the above example data the final result i have to get is 0.498(as
> upper value) and 0.5345(as lower value)
> because 0.5(imaginary reference value) lies in between these two
> values.
>
> Thanks in advance.
data m;
input volume ;
  diff =3D volume - 0.5;
  diffabs =3D abs(volume - 0.5);
  if sign(diff) =3D -1 then limit =3D 1;else
  limit =3D 2;
cards;
0.1234
0.2345
0.3435
0.4567
0.4980
0.4980
0.5345
0.6768
;
run;

proc sort data =3D m out =3D result;
  by limit diffabs ;
run;

data result;
  set result;
  by limit;
  if first.limit;
run;

proc print data =3D result;
run;
quit;
0
11/3/2011 6:28:24 AM
On Nov 3, 1:28=A0am, lchmdream <chunming.li...@gmail.com> wrote:
> On Nov 1, 10:59=A0pm, mahi <mehetrey.mahen...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > data m;
> > input volume ;
> > cards;
> > 0.1234
> > 0.2345
> > 0.3435
> > 0.4567
> > 0.498
> > 0.5345
> > 0.6768
> > ;
> > run;
>
> > i need to get =A0upper and lower values(considering 0.5 as my reference
> > point) which are nearst to .5 value
>
> > from the above example data the final result i have to get is 0.498(as
> > upper value) and 0.5345(as lower value)
> > because 0.5(imaginary reference value) lies in between these two
> > values.
>
> > Thanks in advance.
>
> data m;
> input volume ;
> =A0 diff =3D volume - 0.5;
> =A0 diffabs =3D abs(volume - 0.5);
> =A0 if sign(diff) =3D -1 then limit =3D 1;else
> =A0 limit =3D 2;
> cards;
> 0.1234
> 0.2345
> 0.3435
> 0.4567
> 0.4980
> 0.4980
> 0.5345
> 0.6768
> ;
> run;
>
> proc sort data =3D m out =3D result;
> =A0 by limit diffabs ;
> run;
>
> data result;
> =A0 set result;
> =A0 by limit;
> =A0 if first.limit;
> run;
>
> proc print data =3D result;
> run;
> quit;- Hide quoted text -
>
> - Show quoted text -

Thanks a lot got the output..
0
11/3/2011 6:53:45 PM
Reply: