BookmarkSubscribeRSS Feed
_Manhattan
Quartz | Level 8

Hello,

I want to adapt the page margins of my pdf report in dependency of the odd/even pagenumbers. Till now, I have tried to work with the "leftmargin" etc. options in ods pdf and the ods layout gridded statements. One of the problems I have encountered is that the page numbers are affected by the margin options as well which is not something I want. It would be fine though, if the page numbers are printed at the bottom left/right part of the page according to the odd/even page numbers. Could you help me to achieve the desired result? My code looks like this:

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 CGHK50A CGHK50B CGHK50C DGHK50A DGHK50B DGHK50C;
  datalines;
  10 20 30 40 50  1 2 3 2 3 1 2 3 2 3 1
  15 25 35 45 55  1 3 4 3 2 1 3 4 3 2 1
  5  10 15 20 25  2 2 3 3 2 2 2 3 3 2 1
  20 30 40 50 60  4 3 2 1 1 4 3 2 1 1 1
  25 35 45 55 65  1 1 1 2 3 1 1 1 2 3 1
  5  10 15 20 25  2 2 3 3 2 2 2 3 3 2 1
  20 30 40 50 60  4 3 2 1 1 4 3 2 1 1 1
  25 35 45 55 65  1 1 1 2 3 1 1 1 2 3 1
  ;
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 Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test,1
   AGHK50A,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 Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test Space Test,1
   AGHK50B,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 SpaceTest,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
   CGHK50B,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,4
   CGHK50B,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,4
   CGHK50B,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,4
   DGHK50B,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,5
   DGHK50B,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,5
   DGHK50B,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,5
;

/* 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 varlistA = AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E CGHK50A CGHK50B CGHK50C DGHK50A DGHK50B DGHK50C;


/* 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);
    

/* 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 " "
      FROM work.input_data
      WHERE Sort = &SortID.
      AND Info1 not in ('' 'Variable');
   QUIT;


   ods layout gridded x=1cm columns=1; 
   ods region;
/* Report Variable Information for each Variable */
    proc report data=VariableInfo noheader;
    column Info1 Info2;
    run;
    
	ods layout end;
   
   ods layout gridded x=1cm columns=2;
   %MACRO PrinItemStats(Item=,colPosition=);
      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;
   
   %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;

   ods layout end;
  %end;


%mend Testloop;


/* Style template for page numbers to be put at the bottom of the page */
proc template;
   define style move;
   parent=styles.pearl;
      style PageNo from TitlesAndFooters /
            pretext = "     "
            posttext = " "
            cellpadding=0
            cellspacing=0
            just=c   /* Center */
            vjust=b  /* Bottom */;
   end;
run;


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

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
  • 0 replies
  • 559 views
  • 0 likes
  • 1 in conversation