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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.