看看 SAS XML 映射器。它允许您创建一个映射来读取(并在 9.2 中写入)XML 文件并指定列属性。
如果这是您的 XML 文件:
这显然是文本 20081002 42 42 你可以像这样创建一个 MAP:
<!-- ############################################################ -->
<TABLE name="DATA_TYPE_TEST">
<TABLE-PATH syntax="XPath">/TABLE/DATA_TYPE_TEST</TABLE-PATH>
<COLUMN name="text_char">
<PATH syntax="XPath">/TABLE/DATA_TYPE_TEST/text_char</PATH>
<TYPE>character</TYPE>
<DATATYPE>string</DATATYPE>
<LENGTH>22</LENGTH>
</COLUMN>
<COLUMN name="date_char">
<PATH syntax="XPath">/TABLE/DATA_TYPE_TEST/date_char</PATH>
<TYPE>numeric</TYPE>
<DATATYPE>integer</DATATYPE>
<FORMAT width="9">DATE</FORMAT>
<INFORMAT width="8">ND8601DA</INFORMAT>
</COLUMN>
<COLUMN name="num_char">
<PATH syntax="XPath">/TABLE/DATA_TYPE_TEST/num_char</PATH>
<TYPE>character</TYPE>
<DATATYPE>string</DATATYPE>
<LENGTH>2</LENGTH>
</COLUMN>
<COLUMN name="genuine_num">
<PATH syntax="XPath">/TABLE/DATA_TYPE_TEST/genuine_num</PATH>
<TYPE>numeric</TYPE>
<DATATYPE>integer</DATATYPE>
</COLUMN>
</TABLE>
然后读取 XML 文件:
filename my 'C:\temp\my.xml';
filename SXLEMAP 'C:\temp\MyMap.map';
libname my xml xmlmap=SXLEMAP access=READONLY;
title 'Table DATA_TYPE_TEST';
proc contents data=my.DATA_TYPE_TEST varnum;
run;
proc print data=my.DATA_TYPE_TEST(obs=10);
run;
结果:
Table DATA_TYPE_TEST
The CONTENTS Procedure
Data Set Name MY.DATA_TYPE_TEST Observations
Member Type DATA Variables 4
Engine XML Indexes 0
Created . Observation Length 0
Last Modified . Deleted Observations 0
Protection Compressed NO
Data Set Type Sorted NO
Label
Data Representation Default
Encoding Default
Variables in Creation Order
# Variable Type Len Format Informat Label
1 text_char Char 22 $22. $22. text_char
2 date_char Num 8 DATE9. ND8601DA8. date_char
3 num_char Char 2 $2. $2. num_char
4 genuine_num Num 8 F8. F8. genuine_num
Table DATA_TYPE_TEST
genuine_
Obs text_char date_char num_char num
1 This is obviously text 02OCT2008 42 42