BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I have a question for simplifying my code.  I need to find out duplicate values in my data set. Since there are several data sets in the folder is there way i can use proc contents information to run . Currently i am calling several macro calls like the i called %duplicates(in=ae,seq=aeseq).

 

Instead of calling several   "%duplicates(in=ae,seq=aeseq)' i want to see if i can simplify the code. Please suggest. Thank you

 

proc contents data= sdtm._all_ noprint out= sdtmall(where=(name in ('AESEQ' 'IDVARVAL'))) ; run;

%macro duplicates(in=,seq=);
proc sort data=sdtm.&in. out=_null_ dupout=dups__&in. nodupkey;
       by usubjid &seq.;
  run;
  proc print data=dups__&in. width=min ;
  	   title " Dups in sdtm.&in.";
  	   var usubjid &seq.;
  run;	 
%mend;
%duplicates(in=ae,seq=aeseq);

 

1 REPLY 1
lrudolphi
Obsidian | Level 7

Hi - I would set up some kind of loop to read through your list of data sets. Instead of proc contents, I used the dictionary.tables data set. Then in your macro you can use a %do loop to go through each data set. I've assumed that each of your sequence variables is named like the table, so you can use &in. to achieve the same thing as &seq. If that's not the case, you'd have to get creative to identify the sequence variable as well.

/*Create a list of tables in question*/
proc sql noprint;
	select memname
	into :table_list separated by ' '
	from dictionary.tables
	where upcase(libname) eq 'WORK'
	and   upcase(memname) in ('TEST');
quit;
%let table_count = %sysfunc(countw(&table_list.)); /*Count how many need to be looped across*/

/*Begin process of identifying duplicates*/
%macro duplicates;

	%do i=1 %to &table_count.;
		%let in=%scan(&table_list.,&i.,' ');

		proc sort data=sdtm.&in. out=_null_ dupout=dups__&in. nodupkey;
			by usubjid &in.seq;
		run;

		proc print data=dups__&in. width=min ;
		title "Dups in sdtm.&in.";
		var usubjid &in.seq;
		run;	 

	%end;

%mend;
%duplicates;

  

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1373 views
  • 1 like
  • 2 in conversation