This example uses a
small SAS data set, with a numeric variable that contains values with
a high precision. The following SAS program creates the data set with
an assigned user-defined format, and then exports two XML documents
to show the difference in output:
libname format xml 'C:\My Documents\format.xml'; 1
libname prec xml 'C:\My Documents\precision.xml' xmldouble=internal; 2
data npi; 3
do n=1 to 10;
n_pi = n*3.141592653589793;
output;
end;
format n_pi f14.2;
run;
data format.dbltest; 4
set npi;
run;
data prec.rawtest; 5
set npi;
run;
title 'Drops the Precision'; 6
proc print data=format.dbltest;
format n_pi f14.10;
run;
title 'Keeps the Precision'; 7
proc print data=prec.rawtest;
format n_pi f14.10;
run;
1 |
The
first LIBNAME statement assigns the libref FORMAT to the file that
will store the generated XML document FORMAT.XML. The default behavior
for the engine is that an assigned SAS format controls numeric values.
|
2 |
The
second LIBNAME statement assigns the libref PREC to the file that
will store the generated XML document PRECISION.XML. The XMLDOUBLE=
option specifies INTERNAL, which causes the engine to retrieve the
stored raw values.
|
3 |
The
DATA step creates the temporary data set NPI. The data set has a numeric
variable that contains values with a high precision. The variable
has an assigned user-defined format that specifies two decimal points.
|
4 |
The
DATA step creates the data set FORMAT.DBLTEST from WORK.NPI.
|
5 |
The
DATA step creates the data set PREC.RAWTEST from WORK.NPI.
|
6 |
From
the data set FORMAT.DBLTEST, the PRINT procedure generates the XML
document FORMAT.XML, which contains numeric values controlled by the
SAS format. See XML Document FORMAT.XML. |
7 |
For
the PRINT procedure output, a format was specified in order to show
the precision loss. In the output, the decimals after the second digit
are zeros. See PRINT Procedure Output for FORMAT.DBLTEST. |
8 |
From
the data set PREC.RAWTEST, the PRINT procedure generates the XML document
PRECISION.XML, which contains the stored numeric values. See XML Document PRECISION.XML.
|
9 |
For
the PRINT procedure output, a format was specified in order to show
the retained precision. See PRINT Procedure Output for PREC.RAWTEST. |
XML Document FORMAT.XML
<?xml version="1.0" encoding="iso-8859-1" ?>
<TABLE>
<DBLTEST>
<n>1</n>
<n_pi>3.14</n_pi>
</DBLTEST>
<DBLTEST>
<n>2</n>
<n_pi>6.28</n_pi>
</DBLTEST>
<DBLTEST>
<n>3</n>
<n_pi>9.42</n_pi>
</DBLTEST>
<DBLTEST>
<n>4</n>
<n_pi>12.57</n_pi>
</DBLTEST>
<DBLTEST>
<n>5</n>
<n_pi>15.71</n_pi>
</DBLTEST>
<DBLTEST>
<n>6</n>
<n_pi>18.85</n_pi>
</DBLTEST>
<DBLTEST>
<n>7</n>
<n_pi>21.99</n_pi>
</DBLTEST>
<DBLTEST>
<n>8</n>
<n_pi>25.13</n_pi>
</DBLTEST>
<DBLTEST>
<n>9</n>
<n_pi>28.27</n_pi>
</DBLTEST>
<DBLTEST>
<n>10</n>
<n_pi>31.42</n_pi>
</DBLTEST>
</TABLE>
PRINT Procedure Output for FORMAT.DBLTEST
XML Document PRECISION.XML
<?xml version="1.0" encoding="iso-8859-1" ?>
<TABLE>
<RAWTEST>
<n rawvalue="QRAAAAAAAAA=">1</n>
<n_pi rawvalue="QTJD9qiIWjA=">3.14</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QSAAAAAAAAA=">2</n>
<n_pi rawvalue="QWSH7VEQtGA=">6.28</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QTAAAAAAAAA=">3</n>
<n_pi rawvalue="QZbL4/mZDpA=">9.42</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QUAAAAAAAAA=">4</n>
<n_pi rawvalue="QckP2qIhaMA=">12.57</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QVAAAAAAAAA=">5</n>
<n_pi rawvalue="QftT0UqpwvA=">15.71</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QWAAAAAAAAA=">6</n>
<n_pi rawvalue="QhLZfH8zIdI=">18.85</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QXAAAAAAAAA=">7</n>
<n_pi rawvalue="QhX9u+m7p3U=">21.99</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QYAAAAAAAAA=">8</n>
<n_pi rawvalue="Qhkh+1RELRg=">25.13</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QZAAAAAAAAA=">9</n>
<n_pi rawvalue="QhxGOr7Msrs=">28.27</n_pi>
</RAWTEST>
<RAWTEST>
<n rawvalue="QaAAAAAAAAA=">10</n>
<n_pi rawvalue="Qh9qeilVOF4=">31.42</n_pi>
</RAWTEST>
</TABLE>
PRINT Procedure Output for PREC.RAWTEST