08-06-2013 02:50 AM
i need to get the values nearer to zero, for example in the below data, i need the fifth to eighth values which are the four (as required) nearest values to zero, plz help me with it, is there any specific function for it?
08-06-2013 06:21 AM
I am not aware about any function which will extract the values nearer to zero...However the following code might help you...
proc sort data = have out = want;
if num = 0 then do;
call symput("obs1",_n_ - 2);
call symput("obs2",_n_ + 2);
set want(firstobs = &obs1. obs = &obs2.);
08-06-2013 11:29 AM
There are multiple alternatives.
The simplest mathematical approach is to use abs function to sort and just keep top 4. I'd use a proc sql order by to sort so as to avoid having to create a new variable with the absolute values
create table have as
order by abs(yourcolumnname);