Exporting XML Documents |
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, 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;
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.
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.
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.
The DATA step creates the data set FORMAT.DBLTEST from WORK.NPI.
The DATA step creates the data set PREC.RAWTEST from WORK.NPI.
From the data set FORMAT.DBLTEST, PROC PRINT generates the XML document FORMAT.XML, which contains numeric values controlled by the SAS format.
<?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>
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. Here is the procedure output.
PRINT Procedure Output for FORMAT.DBLTEST
Drops the Precision 1 Obs N_PI N 1 3.1400000000 1 2 6.2800000000 2 3 9.4200000000 3 4 12.5700000000 4 5 15.7100000000 5 6 18.8500000000 6 7 21.9900000000 7 8 25.1300000000 8 9 28.2700000000 9 10 31.4200000000 10
From the data set PREC.RAWTEST, PROC PRINT generates the XML document PRECISION.XML, which contains the stored numeric values.
<?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>
For the PRINT procedure output, a format was specified in order to show the retained precision. Here is the procedure output.
PRINT Procedure Output from PREC.RAWTEST
Keeps the Precision 2 Obs N_PI N 1 3.1415926536 1 2 6.2831853072 2 3 9.4247779608 3 4 12.5663706144 4 5 15.7079632679 5 6 18.8495559215 6 7 21.9911485751 7 8 25.1327412287 8 9 28.2743338823 9 10 31.4159265359 10
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.