Wednesday, January 26, 2011

If the difference of two consecutive number is less then 7, then assign it as missing

options formdlim=' ';

/***************************************************************************
If the difference of two consecutive number is less then 7, then assign it as missing;
*  First, the target numbers will be set as 0; If set as missing ,there is problem;
*  Next, set the zeros to be missing.
***************************************************************************/

data temp;
input d1-d6;
cards;
1 2 7 23 100 1000
2 3 33 54 56 1000
3 . 4 6 44 100
;
run;

data temp1;
   set temp;
array ss(1:6) d1-d6;
array s(1:6) d1-d6;
do i=2 to 6;
  if s[i]-s[i-1]<=7 then do;
     ss[i]=0/* Here if set as missing, there is problems */
        ss[i-1]=0;
        end;
end;
run;

data want;
  set temp1;
  array s d1-d6;
  do i=1 to 6;
    if s[i]=0 then s[i]=.;
   end;
run;


proc print data=want;
run;


No comments:

Post a Comment