Dear,
I am running the below program to find out duplicates in all data sets in sdtm folder. There are (approximately 100) several data sets i think my code works fine but i just want to know if the can be written better way. Please suggest. Thank you
libname sdtm "";
proc contents data= sdtm._all_ noprint out= sdtmall ; run;
data sdtmall1(keep=memname name );
set sdtmall;
run;
%macro duplicates;;
data _null_;
do i=1 to 100;
set sdtmall1;
call symputx(cats('in',i),memname);
call symputx(cats('seq',i),name);
end;
run;
%do i=1 %to 100;
proc sort data=sdtm.&&in&i. out=_null_ dupout=dups__&&in&i. nodupkey;
by usubjid &&seq&i.;
run;
ODS PDF FILE="..pdf";
proc print data=dups__&&in&i. width=min ;
title " Dups in sdtm.&&in&i.";
var usubjid &&seq&i.;
run;
ods pdf close;
%end;
%mend;
%duplicates;
Things I'd change:
But if it works, it works so you don't actually have to change anything.
One possibility is to write your code a temporary file and then execute that:
proc contents data= sdtm._all_ noprint out= sdtmall ; run;
filename tempsas temp;
data _null_;
set sdtmall;
where upcase(name) ne 'USUBJID';
file tempsas;
put
'Proc sort data=sdtm.' memname 'out=_null_ dupout=dups__' memname 'nodupkey;' /
' by usubjid ' name ';' /
'run;' /
'ODS PDF FILE="..pdf";' /
'Title "Dups in sdtm.' memname '";' /
'Proc print data=dups__' memname Width=min; /
' var usubjid ' name ';'/
'run;'/
'ODS PDF close;' /
;
run;
%include tempsas /source2;
Before actually submitting the %INCLUDE statement, you may want to have a look at the TEMPSAS file, and perhaps submit the first block of code to see if everything goes well. A lot easier to debug than macros.
Edit note: after submitting the post, I realised that the code (and your original code as well) will generate a lot of statements like
proc sort;
by usubjid usubjid;
run;
which is probably not what you want, so I added the WHERE clause to avoid that.
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.