DATA Step, Macro, Functions and more

How to import XML file into SAS?

Reply
Contributor
Posts: 73

How to import XML file into SAS?

[ Edited ]

Hi,

I tried using the code in this thread for xml conversion, I got the following error.

7 filename xx temp;

8 libname xx xmlv2 'C:\Users\mgs\Desktop\ems1.xml' automap=replace

8 ! xmlmap=xx;

ERROR: The creation of the XML Mapper file failed.

ERROR: Error in the LIBNAME statement.

9 proc copy in=xx out=work;

10 run;

ERROR: Libref XX is not assigned.

NOTE: Statements not processed because of errors noted above.

NOTE: PROCEDURE COPY used (Total process time):

real time 0.00 seconds

 

can you suggest, what went wrong in the code.

 

Thank you

M

cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.

NOTE: Parsing with high validation.

WARNING: XMLMap parser encountered XML issue

Exception class: org.xml.sax.SAXParseException

ID: <null>

Message: schema_reference.4: Failed to read schema document

'http://nemsis.org/media/XSD_v3/_nemsis_v3.3.4/3.3.4.140328/XSDs/NEMSIS_XSDs_v3.3.4.140328/EMSDataSet...

v3.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root

element of the document is not <xsd:schema>.

Line: 2

Column: 248

Super User
Posts: 22,850

Re: How can I import XML file into SAS?

Posted in reply to Malathi13

What version of SAS are you using? Do you have access to SAS XML Mapper?

Contributor
Posts: 73

Re: How can I import XML file into SAS?

Hi Reeza,

I have SAS 9.4 and I don't have XML mapper.

Super User
Posts: 22,850

Re: How can I import XML file into SAS?

Posted in reply to Malathi13

It’s included in your license so I would suggest installing it, especially if you have complicated XML that the automapper cannot read. Can you post an example of your XML? It doesn't need to be the actual file, but files that are consistent with your data structure. 

Contributor
Posts: 73

Re: How can I import XML file into SAS?

Hi Reeza,

this is how my xml file structure would be, I didn't want to attach it, so copying and pasting it.

 

<?xml version="1.0"?>

-<EMSDataSet>

-<Record>

-<inc_disposition>

      <DispositionID>000000</DispositionID>

     <IncidentID>000000</IncidentID>

     <PatientDisposition>012012</PatientDisposition>

     <Base_Hospital_Contacted>0000</Base_Hospital_Contacted>

</inc_disposition>

 

 

thank you

M

SAS Super FREQ
Posts: 806

Re: How can I import XML file into SAS?

Posted in reply to Malathi13

If your file looks like this, then there should be no problem in read it.

 

See this sample

filename xmlsrc temp;
data _null_;
  infile cards;
  input;
  file xmlsrc;
  put _infile_;
cards4;
<?xml version="1.0"?>
<EMSDataSet>
<Record>
<inc_disposition>
<DispositionID>000000</DispositionID>
<IncidentID>000000</IncidentID>
<PatientDisposition>012012</PatientDisposition>
<Base_Hospital_Contacted>0000</Base_Hospital_Contacted>
</inc_disposition>
</Record>
</EMSDataSet>
;;;;

filename xmlmap temp;

libname xmlin xmlv2 xmlfileref=xmlsrc xmlmap=xmlmap automap=replace;

proc copy in=xmlin out=work;
run;

See also this post, where the XML Mapper is used with XML parsing validation set to minimal

https://communities.sas.com/t5/SAS-Procedures/Error-while-generating-XML-Map-in-XML-Mapper/td-p/1733...

 

Ask a Question
Discussion stats
  • 5 replies
  • 381 views
  • 0 likes
  • 3 in conversation