BookmarkSubscribeRSS Feed
_Manhattan
Quartz | Level 8

Hey guys,

I was wondering if there is any option to suppress the table splitting in ods pdf output? As you can tell from my example code, the table for the "EZGH..." Items is splitting across pages. I would prefer this table to start on a new page. Is there any option that SAS notices that there isn't enough space to print the whole table and prints the table on a new page? I am aware of the startpage options, but I would like to use the available space as efficient as possible. I do not want to use a new page for each procedure as a default.

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 $1000 Info2 $1000;
   input Info1 $ Info2 $ Sort;
   infile datalines delimiter=",";
   datalines;
   Variable,Answer your Item Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,1
   AGHK50A Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,Item A Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,1
   AGHK50B Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,Item B Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,1
   AGHK50C,Item C Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,1
   Variable,Answer your Item Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,2
   BGKO28A,Item A Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,2
   BGKO28B,Item B Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,2
   Variable,Answer your Item Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,3
   EZGH25A,Item A Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,3
   EZGH25B,Item B Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,3
   EZGH25C,Item C Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,3
   EZGH25D,Item D Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,3
   EZGH25E,Item E Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space,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 &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 &varlistE;
  output out=work.mean_ezgh;
run;

%macro meandata;
   %do i = 1 %to %sysfunc(countw(&varlistE));
   %let vmean = %scan(&varlistE, &i);
   
   data work.mean&vmean;
      set work.mean_ezgh (keep=&vmean);
   run;
   
   %end;
%mend meandata;
%meandata;

/* Freq calculation */
%macro freqdata;
   %do i = 1 %to %sysfunc(countw(&varlistA));
   %let vfreq = %scan(&varlista, &i);
   
   proc freq data=work.sample_data;
      tables &vfreq/ out=work.freq&vfreq;
   run;
   
   %end;
%mend freqdata;

%freqdata;


/*** Macro Loop ***/

%macro Testloop;
  %do i = 1 %to %sysfunc(countw(&Sort.));
    %let SortID = %scan(&sort, &i);
    %let VariableA = %scan(&varlistA, &i);
    %let VariableE = %scan(&varlistE, &i);
    



/* Compute Variable Information for each Variable */
    data VariableInfo;
      set work.input_data;
      where Sort = &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 = &SortID.
      AND Info1 not in ('' 'Variable');
   QUIT;


   ods pdf startpage=no; 
   ods layout gridded columns=1; 
   ods region;
/* Report Variable Information for each Variable */
    proc report data=VariableInfo noheader;
      column Info1 Info2;
    run;
    
ods layout end;
    
   %MACRO PrinItemStats(Item=,colPosition=);
   ods layout gridded columns=1;
      ods region;
      %if %sysfunc(exist(freq&Item.)) %then %do; 
         /* Print Frequency Table */
         
         proc report data=freq&Item.;
            column &Item. COUNT PERCENT;
            define &Item / display "&Item.";
            define COUNT / display "Absolut";
            define PERCENT / display "Percent";
         run;
      %end;

      %if %sysfunc(exist(mean&Item.)) %then %do; 
         /* Print Mean Table */
         proc report data=mean&Item.;
            column &Item.; 
         run;
      %end;
   ods layout end;
   %MEND PrinItemStats;


   %local j currItem;
   %LET j=1;
   %LET currItem=%SCAN(&Info1Items.,&j.,%STR( ));


   %DO %WHILE(%LENGTH(&currItem.)>0);


      %PrinItemStats(Item=&currItem.);

      %LET j=%EVAL(&j.+1);
      %LET currItem=%SCAN(&Info1Items.,&j.,%STR( ));
   %END;


  %end;


%mend Testloop;

ods _all_ close;
options  papersize=a4 orientation=portrait leftmargin=1.5cm rightmargin=1.5cm topmargin=1.5cm bottommargin=1.5cm nodate nonumber;
ods pdf file="&yourpath.\LoopTest2.pdf";
%Testloop;
ods pdf close;

Kind regards

 

2 REPLIES 2
ballardw
Super User

Not easily.

ODS RTF has a KEEPN option to do such but even then has some occasionally odd interactions with STARTPAGE and such.

 

About the best approach I can think of is some sort of macro to determine the number lines of input data and guess as to whether a startpage needs to be inserted. I suspect interaction with GRIDDED LAYOUT might complicate that code as well.

 

Note: over control of ODS output will work much better if you isolate the data manipulation parts from the ODS.

Generate all of the data and only include the procs that display desired output, Report, Tabulate, Print, and graphics. Then you would have all of the data pieces available to create parameters for display controls like startpage in the body of a macro creating the ODS output.

_Manhattan
Quartz | Level 8

Thank you for your reply, I was afraid that might be the answer. I was thinking about some kind of macro logic, but now I think it may be easier to transfer this whole code into rtf. Before I read through all the rtf papers though: Does anyone know if rtf has other limitations that will mess with the desired outcome? I have already noticed that ods layout is not available for ods rtf.

 

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
  • 2 replies
  • 523 views
  • 1 like
  • 2 in conversation