Customizing SAS Report Layout

I had an issue with printing SAS Report Layout where a portion of the report that should be printed in 1 block, is split up between 2 pages due to insufficient space. The solution to this is to create our own customized printing preferences using if-else condition.

Below is the full example:

options noDate;

data obj_snsd;
input name $1-$20;
datalines;
sooyoung
seohyun
taeyeon
hyoyeon
jessica
tiffany
sunny
yoona
yuri
;

proc printTo print=print;

data _null_;
   link initialize;   
   link printRecord;
   return;

initialize:
   set obj_snsd;
   file print noTitles;
   retain lnCost pgCtr 0 lnCtr lnMax 5;
   put 'SNSD Member: ' name;
   return;

printRecord:
   lnCost = 1; link printIfMaxLn;
   return;

printIfMaxLn:
   if lnCost + lnCtr > lnMax then link printHeader;
   lnCtr = lnCtr + lnCost;
   return;

printHeader:
   pgCtr = pgCtr + 1; lnCtr = 1;
   put 
   _page_ 
   'SNSD Member List (Page:' pgCtr ')';
   return;

Your custom sas report layout should have 4 variables:
1) lnCtr – line counter (keeps track of the current lines used)
2) pgCtr – page counter (keeps track of the current page)
3) lnCost – line cost (total lines used by a single print block)
4) lnMax – line max (if sum of line counter and line cost is above line max, do page break)

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “Customizing SAS Report Layout