BookmarkSubscribeRSS Feed
dishant
Calcite | Level 5

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

3 REPLIES 3
Patrick
Opal | Level 21

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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Patrick
Opal | Level 21

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 851 views
  • 0 likes
  • 3 in conversation