<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using ODS Layout for customizing PDF Output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899626#M355571</link>
    <description>&lt;P&gt;Cheers Oligolas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;again very helpful input from you, I appreciate it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2023 11:07:17 GMT</pubDate>
    <dc:creator>_Manhattan</dc:creator>
    <dc:date>2023-10-23T11:07:17Z</dc:date>
    <item>
      <title>Using ODS Layout for customizing PDF Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899387#M355502</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;even though there are some very helpful ressources on ods layout, which I used in the past, I do not manage to implement the ods layout/ods region statement successfully in my code. My example code is a slightly modified version of a code that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt; helped me out with (&lt;A href="https://communities.sas.com/t5/SAS-Programming/Using-conditional-logic-to-join-tables-inside-a-do-loop/m-p/886086#M350159" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Using-conditional-logic-to-join-tables-inside-a-do-loop/m-p/886086#M350159&lt;/A&gt;). The desired result should look similar to the Screenshots down below. To summarize my question: How can I incorporate ODS layout within my do-loop to display two (or more) PROC REPORT tables side by side, instead of stacking them vertically?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work kill nolist;run;quit;

%let yourpath=C:\;


/*** Example Data ***/
data work.sample_data;
  input EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;
  datalines;
  10 20 30 40 50  1 2 3 2 3
  15 25 35 45 55  1 3 4 3 2
  5  10 15 20 25  2 2 3 3 2
  20 30 40 50 60  4 3 2 1 1
  25 35 45 55 65  1 1 1 2 3
  ;
run;

data work.input_data;
	length Info1 $9 Info2 $16;
	input Info1 $ Info2 $ Sort;
	infile datalines delimiter=",";
	datalines;
	Variable,Answer your Item,1
	AGHK50A,Item A,1
	AGHK50B,Item B,1
	AGHK50C,Item C,1
	Variable,Answer your Item,2
	BGKO28A,Item A,2
	BGKO28B,Item B,2
	Variable,Answer your Item,3
	EZGH25A,Item A,3
	EZGH25B,Item B,3
	EZGH25C,Item C,3
	EZGH25D,Item D,3
	EZGH25E,Item E,3
;

/* Using proc sql for a Sorting Variable which is used to iterate trough the do-loop */
proc sql noprint;
   select distinct Sort into :Sort separated by " "
   from work.input_data;
quit;

%put &amp;amp;Sort; 

%let varlistE = EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E;
%let varlistA = AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;

/* Mean Calculation */
proc means data=work.sample_data noprint;
  var &amp;amp;varlistE;
  output out=work.mean_ezgh;
run;

%macro meandata;
   %do i = 1 %to %sysfunc(countw(&amp;amp;varlistE));
   %let vmean = %scan(&amp;amp;varlistE, &amp;amp;i);
   
   data work.mean&amp;amp;vmean;
      set work.mean_ezgh (keep=&amp;amp;vmean);
   run;
   
   %end;
%mend meandata;
%meandata;

/* Freq calculation */
%macro freqdata;
   %do i = 1 %to %sysfunc(countw(&amp;amp;varlistA));
   %let vfreq = %scan(&amp;amp;varlista, &amp;amp;i);
   
   proc freq data=work.sample_data;
      tables &amp;amp;vfreq/ out=work.freq&amp;amp;vfreq;
   run;
   
   %end;
%mend freqdata;

%freqdata;


/*** Macro Loop ***/
ods _all_ close;
options leftmargin=.001in rightmargin=.001in topmargin=.001in bottommargin=.001in nodate nonumber;
%macro Testloop;
  %do i = 1 %to %sysfunc(countw(&amp;amp;Sort.));
    %let SortID = %scan(&amp;amp;sort, &amp;amp;i);
    %let VariableA = %scan(&amp;amp;varlistA, &amp;amp;i);
    %let VariableE = %scan(&amp;amp;varlistE, &amp;amp;i);
    
    ods pdf file="&amp;amp;yourpath.\LoopTest.pdf";
    ods pdf startpage=now;
    ods layout start width=19cm height=27cm;

/* Compute Variable Information for each Variable */
    data VariableInfo;
      set work.input_data;
      where Sort = &amp;amp;SortID.;
      drop Sort;
    run;
    
   %local Info1Items;
   %let Info1Items=;
   PROC SQL noprint;
      SELECT distinct Info1 INTO :Info1Items SEPARATED BY " "/*new*/
      FROM work.input_data
      WHERE Sort = &amp;amp;SortID.
      AND Info1 not in ('' 'Variable');
   QUIT;


/* Report Variable Information for each Variable */
    proc report data=VariableInfo noheader;
      column Info1 Info2;
    run;
    
    ods layout end;
    
   %MACRO PrinItemStats(Item=);
      %if %sysfunc(exist(freq&amp;amp;Item.)) %then %do; 
         /* Print Frequency Table */
        ods layout gridded advance=proc columns=2;
         proc report data=freq&amp;amp;Item.;
            column &amp;amp;Item. COUNT PERCENT;
            define &amp;amp;Item / display "&amp;amp;Item.";
            define COUNT / display "Absolut";
            define PERCENT / display "Percent";
         run;
         ods layout end;
      %end;

      %if %sysfunc(exist(mean&amp;amp;Item.)) %then %do; 
         /* Print Mean Table */
         ods layout gridded advance=proc columns=2;
         proc report data=mean&amp;amp;Item.;
            column &amp;amp;Item.; 
         run;
      ods layout end;
      %end;
   %MEND PrinItemStats;


   %local j currItem;
   %LET j=1;
   %LET currItem=%SCAN(&amp;amp;Info1Items.,&amp;amp;j.,%STR( ));
   %DO %WHILE(%LENGTH(&amp;amp;currItem.)&amp;gt;0);

      %PrinItemStats(Item=&amp;amp;currItem.);
      %LET j=%EVAL(&amp;amp;j.+1);
      %LET currItem=%SCAN(&amp;amp;Info1Items.,&amp;amp;j.,%STR( ));
   %END;

  %end;
  ods pdf close;
%mend Testloop;
%Testloop;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sorting1.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88977i9623B55286A7D96C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sorting1.JPG" alt="Sorting1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sorting2.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88979iEBEE823D99843930/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sorting2.JPG" alt="Sorting2.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sorting3.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88980iFB0F16FCF8F4633C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sorting3.JPG" alt="Sorting3.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 13:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899387#M355502</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2023-10-20T13:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using ODS Layout for customizing PDF Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899525#M355549</link>
      <description>&lt;P&gt;Maybe the following could you a help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Here is an alternative way.*/
%let path= c:\temp ;
title;
options nodate nonumber papersize=(2in 2in) ;
ods printer printer=png file="&amp;amp;path.\a.png" style=journal;
proc report data=sashelp.class(obs=6 keep=name age) nowd;
run;

options nodate nonumber papersize=(2in 2in)  ;
ods printer printer=png file="&amp;amp;path.\b.png" style=journal ;
proc report data=sashelp.class(obs=6 keep=name sex) nowd;
run;

options nodate nonumber papersize=(2in 2in) ;
ods printer printer=png file="&amp;amp;path.\c.png" style=journal;
proc report data=sashelp.class(obs=6 keep=name weight) nowd;
run;


options papersize=A4  orientation=portrait;
ods pdf file="&amp;amp;path.\want.pdf" style=journal dpi=300 ;
data x;
x=' ';y=' ';z=' ';output;
x=' ';y=' ';z=' ';output;
run;
title;
proc report data=x nowd noheader style={outputwidth=100% rules=none frame=void};
column x y z;
define _all_/display style={cellwidth=30% bordercolor=white borderwidth=2};

compute z;
n+1;
if n=1 then do;
call define('y','style','style={ preimage="&amp;amp;path\a.png" bordertopcolor=white borderbottomcolor=white borderrightcolor=white borderleftcolor=white}');
end;
if n=2 then do;
call define('x','style','style={ preimage="&amp;amp;path\b.png" bordertopcolor=white borderbottomcolor=white borderrightcolor=white borderleftcolor=white}');
call define('z','style','style={ preimage="&amp;amp;path\c.png" bordertopcolor=white borderbottomcolor=white borderrightcolor=white borderleftcolor=white}');
end;
endcomp;
run;

ods pdf close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1697885965073.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89000iD5D0BD2CBA739BB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1697885965073.png" alt="Ksharp_0-1697885965073.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2023 10:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899525#M355549</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-10-21T10:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using ODS Layout for customizing PDF Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899613#M355570</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you need to work with ods region.&lt;/P&gt;
&lt;P&gt;There is a nice paper that may help you out &lt;A href="https://www.lexjansen.com/phuse/2019/dv/DV03.pdf" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you see the alignment for the 'EZGH' Outputs is not left aligned since the 'second column' is here occupied by the 'Answer your item' column of the previous report.&lt;/P&gt;
&lt;P&gt;You may want to merge all the means tables by hand prior to report them all at one on one table&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc datasets lib=work nolist; delete sample_data input_data mean: VariableInfo freq: ;run ;quit;

%let yourpath=C:\;

ods listing;
/*** Example Data ***/
data work.sample_data;
  input EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;
  datalines;
  10 20 30 40 50  1 2 3 2 3
  15 25 35 45 55  1 3 4 3 2
  5  10 15 20 25  2 2 3 3 2
  20 30 40 50 60  4 3 2 1 1
  25 35 45 55 65  1 1 1 2 3
  ;
run;

data work.input_data;
   length Info1 $9 Info2 $16;
   input Info1 $ Info2 $ Sort;
   infile datalines delimiter=",";
   datalines;
   Variable,Answer your Item,1
   AGHK50A,Item A,1
   AGHK50B,Item B,1
   AGHK50C,Item C,1
   Variable,Answer your Item,2
   BGKO28A,Item A,2
   BGKO28B,Item B,2
   Variable,Answer your Item,3
   EZGH25A,Item A,3
   EZGH25B,Item B,3
   EZGH25C,Item C,3
   EZGH25D,Item D,3
   EZGH25E,Item E,3
;

/* Using proc sql for a Sorting Variable which is used to iterate trough the do-loop */
proc sql noprint;
   select distinct Sort into :Sort separated by " "
   from work.input_data;
quit;

%put &amp;amp;Sort; 

%let varlistE = EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E;
%let varlistA = AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;

/* Mean Calculation */
proc means data=work.sample_data noprint;
  var &amp;amp;varlistE;
  output out=work.mean_ezgh;
run;

%macro meandata;
   %do i = 1 %to %sysfunc(countw(&amp;amp;varlistE));
   %let vmean = %scan(&amp;amp;varlistE, &amp;amp;i);
   
   data work.mean&amp;amp;vmean;
      set work.mean_ezgh (keep=&amp;amp;vmean);
   run;
   
   %end;
%mend meandata;
%meandata;

/* Freq calculation */
%macro freqdata;
   %do i = 1 %to %sysfunc(countw(&amp;amp;varlistA));
   %let vfreq = %scan(&amp;amp;varlista, &amp;amp;i);
   
   proc freq data=work.sample_data;
      tables &amp;amp;vfreq/ out=work.freq&amp;amp;vfreq;
   run;
   
   %end;
%mend freqdata;

%freqdata;


/*** Macro Loop ***/

%macro Testloop;
  %do i = 1 %to %sysfunc(countw(&amp;amp;Sort.));
    %let SortID = %scan(&amp;amp;sort, &amp;amp;i);
    %let VariableA = %scan(&amp;amp;varlistA, &amp;amp;i);
    %let VariableE = %scan(&amp;amp;varlistE, &amp;amp;i);
    



/* Compute Variable Information for each Variable */
    data VariableInfo;
      set work.input_data;
      where Sort = &amp;amp;SortID.;
      drop Sort;
    run;
    
   %local Info1Items;
   %let Info1Items=;
   PROC SQL noprint;
      SELECT distinct Info1 INTO :Info1Items SEPARATED BY " "/*new*/
      FROM work.input_data
      WHERE Sort = &amp;amp;SortID.
      AND Info1 not in ('' 'Variable');
   QUIT;


   ods pdf startpage=now;&lt;BR /&gt;  /*one row for variable report and one for the freq/mean reports as much columns as there are freq or means reports*/
   ods layout gridded columns=%sysfunc(countw(&amp;amp;Info1Items.)) rows=2 ; 
   ods region column=1 row=1;
/* Report Variable Information for each Variable */
    proc report data=VariableInfo noheader;
      column Info1 Info2;
    run;
    

    
   %MACRO PrinItemStats(Item=,colPosition=);
      ods region  row=2;
      %if %sysfunc(exist(freq&amp;amp;Item.)) %then %do; 
         /* Print Frequency Table */
         
         proc report data=freq&amp;amp;Item.;
            column &amp;amp;Item. COUNT PERCENT;
            define &amp;amp;Item / display "&amp;amp;Item.";
            define COUNT / display "Absolut";
            define PERCENT / display "Percent";
         run;
      %end;

      %if %sysfunc(exist(mean&amp;amp;Item.)) %then %do; 
         /* Print Mean Table */
         proc report data=mean&amp;amp;Item.;
            column &amp;amp;Item.; 
         run;
      %end;
   %MEND PrinItemStats;


   %local j currItem;
   %LET j=1;
   %LET currItem=%SCAN(&amp;amp;Info1Items.,&amp;amp;j.,%STR( ));

   %put ERROR:# &amp;amp;=Info1Items. %sysfunc(countw(&amp;amp;Info1Items.));

   %DO %WHILE(%LENGTH(&amp;amp;currItem.)&amp;gt;0);


      %PrinItemStats(Item=&amp;amp;currItem., colPosition=&amp;amp;j.);

      %LET j=%EVAL(&amp;amp;j.+1);
      %LET currItem=%SCAN(&amp;amp;Info1Items.,&amp;amp;j.,%STR( ));
   %END;
      ods layout end;



  %end;


%mend Testloop;

ods _all_ close;
options  papersize=a4 orientation=landscape leftmargin=1.5cm rightmargin=1.5cm topmargin=1.5cm bottommargin=1.5cm nodate nonumber;
ods pdf file="&amp;amp;yourpath.\LoopTest.pdf";
%Testloop;
ods pdf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2023 09:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899613#M355570</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-10-23T09:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using ODS Layout for customizing PDF Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899626#M355571</link>
      <description>&lt;P&gt;Cheers Oligolas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;again very helpful input from you, I appreciate it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 11:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ODS-Layout-for-customizing-PDF-Output/m-p/899626#M355571</guid>
      <dc:creator>_Manhattan</dc:creator>
      <dc:date>2023-10-23T11:07:17Z</dc:date>
    </item>
  </channel>
</rss>

