<p>I need to control the data type when reading XML data in SAS. The XML data are written and accessed using the XML libname engine in SAS.</p>

<p>SAS seems to guess the data type based on the contents of a column: If I write "20081002" to my XML data in a character column, it will be read back in as a numerical variable.</p>

<p>An example:</p>

<pre><code>filename my_xml '/tmp/my.xml'; * Yes, I use SAS on Unix *;
libname my_xml XML;

data my_xml.data_type_test;
  text_char="This is obviously text";
  date_char="20081002";
  num_char="42";
  genuine_num=42;
run;

proc copy inlib=my_xml outlib=WORK;
run;

libname my_xml;
filename my_xml CLEAR;
</code></pre>

<p>Only the last column is defined as numerical data type in the XML data, but when I copy it into my WORK library, only the column <em>text_char</em> is character. The other 3 are now numeric.</p>

<p>How can I control the data type when reading XML data in SAS?</p>

I think you need to define some xml specific options whith your libname XML statement for export go:
```
```
libname my_xml_out XML XMLMETA=SCHEMADATA;
```
```
To include the data schema. Also, you might want to save the XML schema to a separate file for later import:
```
```
libname my_xml_in XML XMLSCHEMA='external-file'
```
```
after you exported the schema using
```
XMLMETA=SCHEMA
```
of course.
I think
this is the documentation you need
.
Apart from that liberal use of format statements on original dataset creation is recommended.