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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.