BookmarkSubscribeRSS Feed
_Manhattan
Quartz | Level 8

Hello everyone,

 

I would like to use ODS Layout as in my last post (https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/89962...) to customize my PDF output. Unfortunately, I could use the sample code provided by @Oligolas only to solve some of my issues. When I try to apply the whole thing to my original data, I don't fully understand how to use ODS REGION to influence the output the way I want. Even if I use different data now (see attachment), the output should look approximately as shown in the screenshots below. When you run the code you can see that ods region is ignored (which is not suprising as the Log shows some warnings.). Questions: How can I modify my ods region statements so that I have more (or full) control over my output? How can I avoid getting all of these error messages?

 

/* Data path and libname */
%let epath = yourpathE;
Libname d = yourpathD;


/* Macro Variable Sort for Sorting */
proc sql noprint;
  select distinct Sort into :Sort separated by " "
  from d.Excelitems;
quit;

/* Start of Macro for Report */
options leftmargin=.001in rightmargin=.001in topmargin=.001in bottommargin=.001in nodate nonumber;
ods _all_ close;
ods escapechar="^";

%macro TableTest;
  %do i = 1 %to 3;
    %let SortID = %scan(&Sort., &i.);
	ods html close;
    

/* Set Datasets for Variable Information */
    data d.SourceInfo;
    	set d.excelitems;
    	where Sort = &SortID. and Part = "a";
    	drop Sort Part;
    run;
    
    data d.VariableInfo;
    	set d.excelitems;
    	where Sort = &SortID. and Part = "b";
    	drop Sort Part;
    run;

/* Extract Items for Iteration */
   %local Info1Items; 
   proc sql noprint; 
      select distinct Info1 into :Info1Items separated by " "
      from d.ExcelItems 
      where Sort = &SortID.;
   quit; 


ods pdf startpage=no;
ods layout gridded columns=%sysfunc(countw(&Info1Items.)) rows=2;
/* Print Variable Information */
    proc report data=d.Sourceinfo noheader;
    	column Info1 Info2 Bsort;
    	define Info1 / display;
    	define Info2 / display;
    	define Bsort / noprint;
    	compute Bsort;
    		if Bsort = "*" then do;
    		call define (_ROW_,"style","style={font_weight=bold fontsize=10pt}");
    		end;
    	endcomp;
    run;
    
    proc report data=d.VariableInfo noheader;
    	column Info1 Info2 Bsort;
    	define Info1 / display;
    	define Info2 / display;
    	define Bsort / noprint;
    	compute Info1;
    		Info1 = tranwrd(Info1,"Kodierung","^{style[fontweight=bold]Kodierung}");
    	endcomp;
    	compute Bsort;
    		if Bsort ="*" then do;
    		call define (_row_, "style", "style={backgroundcolor=lightgrey fontweight=bold}");
    		end;
    	endcomp;
    run;

/* Macro to merge Variable Information with Freq/Mean Tables */
%macro PrintItem(Item=,colPosition=);
ods region row=2 style={background=lightblue};
/* Print Freq Tables */
	%if %sysfunc(exist(d.F&Item.)) %then %do;
	ods region row=2 style={background=lightblue};
      proc report data=d.F&Item.;
        column &Item. n pct pct_se;
        define &Item. / display "&Item" style(header)=[backgroundcolor=lightgrey];
        define n / display "Absolut" style(header)=[backgroundcolor=lightgrey];
        define pct / "Prozent" width=12 format=6.2 style(header)=[backgroundcolor=lightgrey];
        define pct_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
      run;
    %end;
    
/* Print Mean Tables */
	%if %sysfunc(exist(d.M&Item.)) %then %do;
      proc report data=d.M&Item.;
        column dvar mnx mnx_se sdx Min Max n; 
        define dvar / display "Variable" style(header)=[backgroundcolor=lightgrey];
        define mnx / display "M" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define mnx_se / display "(SE)" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define sdx / display "SD" format=6.2 style(header)=[backgroundcolor=lightgrey];
        define Min / display "Min" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define Max / display "Max" format=6.0 style(column) = {just = center} style(header)=[backgroundcolor=lightgrey];
        define n / display "n" style(header)=[backgroundcolor=lightgrey];
      run;
	%end; ;
%mend PrintItem;
 
   %local j currItem; 
   %let j=1; 
   %let currItem=%scan(&Info1Items.,&j.,%str( )); 
   
   %do %while(%length(&currItem.)>0); 
  
      %PrintItem(Item=&currItem., colPosition=&j.); 
      %let j=%eval(&j.+1); 
      %let currItem=%scan(&Info1Items.,&j.,%str( )); 
      
   %end; 
   
ods layout end;  
   
  %end;
  
%mend TableTest;

/* Print PDF */
options  papersize=a4 orientation=portrait leftmargin=1.5cm rightmargin=1.5cm topmargin=1.5cm bottommargin=1.5cm nodate nonumber;
ods listing close;
ods pdf file="&epath\TableTest.pdf";
%TableTest;
ods pdf close;

(some of the) Log Messages:

 WARNING: COLUMN_GUTTER causes WIDTH to exceed available space for PDF destination. 
          Setting COLUMN_GUTTER=29 to avoid paneling.
 WARNING: COLUMN_GUTTER causes WIDTH to exceed available space for PDF destination. 
          Setting COLUMN_GUTTER=28 to avoid paneling.
 WARNING: LAYOUT is full. Implicitly closing LAYOUT.
 WARNING: GRIDDED Layout exceeds the available space for PDF destination and will be 
          paneled.
 WARNING: COLUMN_GUTTER causes WIDTH to exceed available space for PDF destination. 
          Setting COLUMN_GUTTER=27 to avoid paneling.
 WARNING: COLUMN_GUTTER causes WIDTH to exceed available space for PDF destination. 
          Setting COLUMN_GUTTER=26 to avoid paneling.
 WARNING: COLUMN_GUTTER causes WIDTH to exceed available space for PDF destination. 
          Setting COLUMN_GUTTER=25 to avoid paneling.
 WARNING: REGION found but no LAYOUT open for the destination.  Region will be 
          ignored.
 WARNING: REGION found but no LAYOUT open for the destination.  Region will be 
          ignored.
 WARNING: REGION found but no LAYOUT open for the destination.  Region will be 
          ignored.
 WARNING: REGION found but no LAYOUT open for the destination.  Region will be 
          ignored.
 WARNING: REGION found but no LAYOUT open for the destination.  Region will be 
          ignored.
 WARNING: Missing LAYOUT_START statement.  This statement will be ignored.

Screenshots, that show more or less desired result:

Bsp 44.JPG

Bsp 43.JPG

Bsp 42.JPG

 

Kind regards

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 0 replies
  • 927 views
  • 0 likes
  • 1 in conversation