Category Archives: Output Delivery System (ODS)

Print Loop Macro

Note: This program was developed on a 32-bit Windows system.

Output Data Cleaning Reports by Table Name and ID

%macro printLoop(dset=,pdfDest=,rpt=);
data _null_; 
     retain N 0;
     set &dset. (keep=idnum iecnum) end=last;
     call symput("iecnum"||trim(left(_N_)),compress(iecnum));
     call symput("idnum"||trim(left(_N_)),compress(idnum));
     if last then call symput('N',trim(left(_N_)));        
run;
%do printLoop = 1 %to &N.;
data foo; set &dset.(where=(idnum="&&idnum&printLoop"));
run;
ods pdf body  = "&pdfDest.&d._&&idnum&printLoop...pdf"
        style = sasweb
        bookmarkgen=yes
        startpage=yes
        author="Columbia University Medical Center";
%inc &rpt.;
ods pdf close;
%end;
%mend printLoop;

Download SAS Program

To Output Data Cleaning Reports by Site, Table Name, and ID replace the PDF statement in the program with this statement below:

ods pdf body  ="&pdfDest.&&iecnum&printLoop&d._&&idnum&printLoop...pdf"

Program to Check for Variable Length Discrepancies Among Datasets

Note: This program was developed on a 32-bit Windows system.

libname archive 'S:pathtosaslib';
proc datasets lib=archive;
     contents data=_all_
     out=work.foo(keep=memname name length
     where=(name in('IDNUM','SUBINIT')));
quit;
proc sort data=foo;
     by name;
run;
ods listing;
ods pdf file="S:pathtooutput.pdf"
        style=sasweb;
proc report data=foo nowd;
     by name;
     column memname name length;
     define memname / display;
     define name / display ;
     define length / display ;
title 'Variable Length Discrepancies Among Datasets';
title2 'March 25th, 2011 Data Release';
run;
ods pdf close;

Download SAS Program
View Output

Missing Data Summary Macro

Note: This program was developed on a 32-bit Windows system.

%macro missingDataSummary(dset=);
ods listing close;
ods pdf body="&pdfDest.&dset._missing.pdf";

proc contents data=&dset. varnum out=foo(keep=name) noprint;
run;

data _null_; 
     retain N 0;
     set foo end=last;
     call symput("name"||trim(left(_N_)),compress(NAME));
     if last then call symput('N',trim(left(_N_)));        
run;

%let obs = '';

data foo; set &dset.;
format _numeric_ missing. _character_ $mischar.;
run;

data miss; 
     set foo;
     %do printLoop = 1 %to &N.; 
         if missing(&&name&printLoop) then output;
	 keep &&name&printLoop;
     %end; *close printLoop; 
keep iecnum idnum;
run;

proc sort data=miss nodup;
     by idnum;
run;

proc sql noprint; 
     select count(*) into: obs
     from WORK.miss;
quit;

%if &obs > 0 %then %do; 
proc contents data=miss varnum out=miss2(keep=name) noprint;
run;

data _null_; 
     retain N 0;
     set miss2 end=last;
     call symput("name"||trim(left(_N_)),compress(NAME));
     if last then call symput('N',trim(left(_N_)));        
run;

     %do printLoop = 1 %to &N.; 
         ods proclabel="&&name&printLoop";
         proc print data=miss noobs;
              where missing(&&name&printLoop);
              var iecnum idnum &&name&printLoop;
 	          title Missing &dset Data: &&name&printLoop; 
         run;
      %end; 
%end;
ods pdf close;
ods listing;
title;
%mend missingDataSummary;

Download SAS Program

red titles and/or footnotes

How to create a red title or footnote in an ODS-based report:

footnote "*Blah Blah Blah";