DATA Step, Macro, Functions and more

How to comapre

Reply
Contributor
Posts: 52

How to comapre

Hi All,


Please find the below my Screen shot.

I want to compare Each PatientID by Each Respective column to check Duplicate Dates, Please Help me on this

Capture.PNG

Regards,

Dishant Parikh

Respected Advisor
Posts: 3,892

Re: How to comapre

Your table looks like the result of a transpose. It would be easier to look for such duplicates before transposing you data, eg. by using Proc Sort with NODUPKEY and writing duplicates to a 2nd data set (documented under Proc Sort),

or by using a data step like:

data want Duplicates;

     set have;

     by PatientID ActualDate;

     if first.ActualDate then output want;

     else output Duplicates;

run;

Super User
Super User
Posts: 7,401

Re: How to comapre

Patrick is correct, do the check before transposing.  However, if you really must do it after transposing then you have arrays which could be used, something like:

data have;
  attrib patientid format=best. _0 _1 _2 _3 format=date9.;
  patientid=1; _0='05may2011'd; _1='19may2011'd; _2='14jul2011'd; _3='05aug2011'd; output;
  patientid=3; _0='28apr2011'd; _1='13may2011'd; _2='25jul2011'd; _3='25jul2011'd; output;
run;

data want (drop=i j);
  set have;
  attrib flag format=$1.;
  array _{3};
  do i=1 to 3;
    do j=1 to 3;
      if i ne j and _{i}=_{j} then flag="Y";
    end;
  end;
run;

I don't say that's a good way of doing things, just its possible.

Respected Advisor
Posts: 3,892

Re: How to comapre

Another coding option which by pre-sorting the array avoids the need to create something close to a Cartesian product.

data want(drop=ind);

  set have;

  attrib dup_flag format=$1.;

  array dates {*} _: ;

  dup_flag='N';

  call sortn(of dates(*));

  do ind=dim(dates) to 2 by -1 while(not missing(dates(ind-1)));

    if dates(ind) = dates(ind-1) then

      do;

        dup_flag='Y';

        leave;

      end;

  end;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 242 views
  • 0 likes
  • 3 in conversation