SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to read an XML file in SAS without SAS XML Mapper

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

How to read an XML file in SAS without SAS XML Mapper

Hi All,

 

I have an XML file, whcih i want to read in SAS. I tried reading the file through the libname xml engine.

libname myxxml xml 'c:\users\mine\desktop\project.xml';

 

however the same is not accessible, as it needs an XML Mapper file to read it.

 

I have read that XML Mapper is a different software and it will create a xml mapper file which i need to use to read the xml.

 

Can anyone help me if they have any idea how we can create the xml mapper file and read the xml file in the bach mode?

 

Thanks in advance


Cheers from India!

Manjeet

Accepted Solutions
Solution
‎12-26-2016 02:26 AM
Super User
Posts: 9,691

Re: How to read an XML file in SAS without SAS XML Mapper

Not sure if the following could work.

filename xx temp;
libname xx xmlv2 '/folders/myfolders/temp.xml' automap=replace xmlmap=xx ;

libname zz cvp '/folders/myfolders/' cvpmult=2;
proc copy in=xx out=zz noclone;
run;

View solution in original post


All Replies
Frequent Contributor
Posts: 96

Re: How to read an XML file in SAS without SAS XML Mapper

You can create library to read XML files in BASE SAS,

sample libname syntax:

libname out xml 'C:\xml_folder\sample_xml file.xml';

 

For more details please refer this links:

http://www2.sas.com/proceedings/sugi29/119-29.pdf

http://support.sas.com/resources/papers/proceedings12/253-2012.pdf

 

Contributor
Posts: 52

Re: How to read an XML file in SAS without SAS XML Mapper

Thanks, but that won't work, as the xml uses xml map. I already had tried and mentioned the same in my original post.

 


Cheers from India!

Manjeet
Respected Advisor
Posts: 3,908

Re: How to read an XML file in SAS without SAS XML Mapper

@mnjtrana

The articles @Kalind_Patel posted will give you the necessary details of how you can create such an XMLMap (and you can download the tool itself from the link I've posted in my previous answer).

Contributor
Posts: 52

Re: How to read an XML file in SAS without SAS XML Mapper

This is an ongoing process and everytime the xml is different, so everytime a new xml map needs to be generated. also this all needs to be done in batch, non interactive. 

 

So i think the solution suggested won't work,


Cheers from India!

Manjeet
Respected Advisor
Posts: 3,908

Re: How to read an XML file in SAS without SAS XML Mapper

@mnjtrana

With any data exchange you need to have defined data structures. In an XML world an XSD (XML Schema Definition) provides such a definition. If you create your XMLMap using an XSD then the XML's you get can vary but as long as they conform with the XSD (which they must to be valid) your XMLMap will work and you will be able to read the data into SAS.

 

If you don't have an XSD then you need to make sure that you use an XML which contains all the data elements possible.

 

There is no other way of making this work and it's on this level also no more SAS specific but would apply to any application parsing the source XML. You need to know what you have to expect (=XSD).

Respected Advisor
Posts: 3,908

Re: How to read an XML file in SAS without SAS XML Mapper

You can download the XML mapper from here at no extra cost:

https://support.sas.com/downloads/package.htm?pid=1278

 

You can use an XML as input for the tool to create an XMLMAP but if this is for an ongoing process then make sure that the XML you use for this contains all the elements possible or even better use the related XSD for creation of the XMLMAP.

 

Super User
Posts: 9,691

Re: How to read an XML file in SAS without SAS XML Mapper

Try XMLV2 engine. if you are lucky, SAS will generate that MAP for you automatically.

 

filename xx temp;
libname xx xmlv2 '/folders/myfolders/temp.xml' automap=replace xmlmap=xx;
proc copy in=xx out=work noclone;
run;
Contributor
Posts: 52

Re: How to read an XML file in SAS without SAS XML Mapper

Thanks @Ksharp that worked, however for a few XML's the data is getting truncated.

 

LOG:

 

WARNING: Data Truncation occured on variable Taskcode Column length=469 Additional length = 603.

 

This is a data length warning. Do we have some option so that all the data can be taken in, instead of truncation.


Cheers from India!

Manjeet
Solution
‎12-26-2016 02:26 AM
Super User
Posts: 9,691

Re: How to read an XML file in SAS without SAS XML Mapper

Not sure if the following could work.

filename xx temp;
libname xx xmlv2 '/folders/myfolders/temp.xml' automap=replace xmlmap=xx ;

libname zz cvp '/folders/myfolders/' cvpmult=2;
proc copy in=xx out=zz noclone;
run;

Respected Advisor
Posts: 3,908

Re: How to read an XML file in SAS without SAS XML Mapper

[ Edited ]

@mnjtrana

If you're implementing for some user triggered process then what @Ksharp proposed is a very acceptable approach, but if you're implementing for a production worthy scheduled batch process then you do need to know your data in advance and I'd call anything not using a pre-defined XML map as sub-standard.

The length issue you've just encountered should give you a hint why I'm making such a strong statement. 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 639 views
  • 3 likes
  • 4 in conversation