Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:20:18+00:00 2026-05-11T05:20:18+00:00

I need to control the data type when reading XML data in SAS. The

  • 0

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.

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.

An example:

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; 

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 text_char is character. The other 3 are now numeric.

How can I control the data type when reading XML data in SAS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:20:18+00:00Added an answer on May 11, 2026 at 5:20 am

    Take a look at the SAS XML Mapper. It allows you to create a map to read (and wrte in 9.2) XML files and specifying column attributes.

    If this is your XML file:

    This is obviously text 20081002 42 42 You could create a MAP like this:

    <!-- ############################################################ --> <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> 

    And then read the XML file:

    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; 

    Result:

    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 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 321k
  • Answers 321k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since it doesn't seem like anyone has done this before… May 14, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer I did run that benchmark too. That piece of code… May 14, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer Well, I have decided to use for_each instead of transform… May 14, 2026 at 12:40 am

Related Questions

I find myself constantly running into a situation where I have a set of
From reading here and around the net, I'm close to assuming the answer is
I need to create several combo boxes to represent enumeration values. I want the
I am actually finding that chkContactType.Items is empty when I step through the code.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.