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
Regards,
Dishant Parikh
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;
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.
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.