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
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;
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
Thanks, but that won't work, as the xml uses xml map. I already had tried and mentioned the same in my original post.
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).
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,
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).
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.
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;
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.
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;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.