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;

  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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