![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
The sample code on the Full Code tab demonstrates how to center numbers within a column but also have them aligned on the decimal point. SAS® and the ODS destinations are capable of applying only one justification. The following steps are needed to obtain the desired output:
Spacing and alignment issues are impacted by the font that is being used. SAS Technical Support recommends that you use a monospace, or non-proportional, font such as Courier. A monospace font means that each character takes up the same amount of space. For example, an ‘i’ is just as wide as an ‘m’. It is not possible to get exact alignment without using a monopace font. If your report specifications require the use of a proportional font, the non-breaking space function NBSPACE might help line up the information when indenting or shifting text.
RTF and PDF handle the placement of values in two different ways. RTF ensures that the column is wide enough and then adds RTF-specific code to line up the decimal points. PDF measures each piece and meticulously places it in a specific spot on the page. In some instances, PDF has the advantage when aligning values because it measures everything before the document is rendered. For RTF documents, SAS puts the information in the file and Microsoft Word is responsible for how everything is displayed. An advantage of RTF is that RTF control characters can be inserted to assist with alignment.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
The ASIS=ON attribute prevents the trailing spaces from being removed in the output and shifts the value the appropriate number of spaces to the left.
The code for applying the format to the column is slightly cumbersome but is necessary when the values have a varying number of decimal places. If your values have the same number of decimal places, only one format is needed and it can be applied with one CALL DEFINE statement.
/* Set a monospace font */
proc template;
define style styles.mypdf;
parent=styles.printer;
style fonts /
'BatchFixedFont' = ("Courier",10pt)
'TitleFont2' = ("Courier",10pt)
'TitleFont' = ("Courier",10pt)
'StrongFont' = ("Courier",10pt)
'EmphasisFont' = ("Courier",10pt)
'FixedEmphasisFont' = ("Courier",10pt)
'FixedStrongFont' = ("Courier",10pt)
'FixedHeadingFont' = ("Courier",10pt)
'FixedFont' = ("Courier",10pt)
'headingEmphasisFont' = ("Courier",10pt)
'headingFont' = ("Courier",10pt)
'docFont' = ("Courier",10pt);
end;
define style styles.myrtf;
parent=styles.rtf;
style fonts /
'BatchFixedFont' = ("Courier",10pt)
'TitleFont2' = ("Courier",10pt)
'TitleFont' = ("Courier",10pt)
'StrongFont' = ("Courier",10pt)
'EmphasisFont' = ("Courier",10pt)
'FixedEmphasisFont' = ("Courier",10pt)
'FixedStrongFont' = ("Courier",10pt)
'FixedHeadingFont' = ("Courier",10pt)
'FixedFont' = ("Courier",10pt)
'headingEmphasisFont' = ("Courier",10pt)
'headingFont' = ("Courier",10pt)
'docFont' = ("Courier",10pt);
end;
run;
data decimal;
input site $ number1 number2 number3;
datalines;
A 8 8.8 8.8
B 10 10.1 10.25
C 100 100.0 100
;
run;
/* PDF */
/* The PROC FORMAT code in this example places spaces behind the
digit selectors for the one and zero decimal formats. */
proc format;
picture twodec low-high='009.99';
picture onedec low-high='009.9 ';
picture nodec low-high='009 ';
run;
ods pdf file='sample.pdf' notoc style=styles.mypdf;
title 'Center Justification and Decimal Alignment';
proc report data=decimal nowd style(column)=[just=c asis=on];
column site number1 number2 number3;
compute number1;
len = lengthn(scan(put(number1.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
compute number2;
len = lengthn(scan(put(number2.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
compute number3;
len = lengthn(scan(put(number3.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
run;
ods pdf close;
/* RTF */
/* The PROC FORMAT code in this example places RTF control characters for
non-breaking spaces behind the digit selectors for the one and zero
decimal formats. The attribute PROCTECTSPECIALCHARS=OFF is imperative
in this code because it forces the control characters to be interpreted
correctly by Microsoft Word. */
proc format;
picture twodec low-high='009.99';
picture onedec low-high='009.9\~';
picture nodec low-high='009\~\~\~';
run;
ods rtf file='sample.rtf' style=styles.myrtf;
title 'Center Justification and Decimal Alignment';
proc report data=decimal nowd style(column)=[just=c asis=on protectspecialchars=off];
column site number1 number2 number3;
compute number1;
len = lengthn(scan(put(number1.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
compute number2;
len = lengthn(scan(put(number2.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
compute number3;
len = lengthn(scan(put(number3.sum,best8.),2,'.'));
if len = 0 then call define(_col_,'format','nodec.');
else if len = 1 then call define(_col_,'format','onedec.');
else if len = 2 then call define(_col_,'format','twodec.');
endcomp;
run;
ods rtf close;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Date Modified: | 2019-09-16 13:12:39 |
Date Created: | 2013-06-19 12:54:37 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Aster Data nCluster on Linux x64 | ||
DB2 Universal Database on AIX | ||||
DB2 Universal Database on Linux x64 | ||||
Greenplum on Linux x64 | ||||
Netezza TwinFin 32bit blade | ||||
Netezza TwinFin 32-bit SMP Hosts | ||||
Netezza TwinFin 64-bit S-Blades | ||||
Netezza TwinFin 64-bit SMP Hosts | ||||
Teradata on Linux | ||||
z/OS | ||||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Ent | ||||
Microsoft Windows 8 Pro | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 for x64 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |