I've a requirement to convert a SAS dataset to XML file. Although I could do this, I'm not certain on how to validate the XML file to know whether the conversion has happened rightly. Appreciate if someone of you guide me to know the way to validate the XML file.
What do you mean by validate? This could mean:
Syntax checking the XML to ensure it is well structured.
Validating the XML against a DSD to ensure rules are followed.
Checking the data against the data in your dataset to ensure the write was correct.
Plus maybe others.
For syntax (and DSD, though you did not mention you had one), then you can use any of the XML tools out there, for instance an online one:
https://www.xmlvalidation.com/
To check the data, you would need to do one of the following:
Read the data back in and proc compare
Get someone else to program the XML output and text compare the output files
I've a XML Mapper installed in my machine. Is there is an way to validate the XML file in XML Mapper?
That is the small free tool from SAS right? If so that is just for building the scheme to import data from XML, don't think it does anything else. There are loads of tools out there, like the online one I sent.
The question is: What do you want to validate against? A DTD, an XSD,...?
If there is an XSD and you need to convert a SAS table to XML which complies with this XSD:
You can use the SAS XML Mapper to generate a SAS XMLMap.
You then use this SAS XMLMap as part of your libname statement with the XML engine to generate the XML.
http://support.sas.com/kb/48/825.html
As for validating the generated XML against the XSD which SAS used to generate the XML:
You can't really use SAS to test if SAS got it right. So if you really want to validate the generated XML against the XSD the you need to use some 3rd party product. There is for example Java stuff out there which can do such validation.
I want to create the mapping file from XML file. I've opened the XML file from SAS XML Mapper and then I went on to see the tab 'XML map'. But I'm not certain whether that is the mapping file. Could you please give me some insights here?
As an alternate option, I tried the following code in SAS EG 7.12, but I end up with error as follows.
24 libname xmlfile xmlv2 xmlmap=mapfile automap=replace;
ERROR: The XMLV2 engine cannot be found.
ERROR: Error in the LIBNAME statement.
25
26 proc copy in=xmlfile out=work;
27 run;
So, you open the XML file you already have in XML mapper? In which case you are in the process of creating the map file. The XML mapper is a tool designed to map the XML file into a dataset, the output map can then be used in code.
As for your error, are you up to date with EG?
Appreciate if you could expand this sentence by referencing the documentation. 'The XML mapper is a tool designed to map the XML file into a dataset, the output map can then be used in code'
I'm not upto date in SAS EG. I've not used XML file in the past and therefore seeking your help.
See:
If your EG version is not current enough to include the xmlv2 engine then try the xml engine:
libname tmp xml "....xml";
Or you may have to read and parse it yourself, depending on the complexity. Does the file open in Excel? A lot of the time Excel's XML reader can process it for you and then you could save as CSV file and import that. Might be simpler.
I've used the following code to generate the mapping file, but I end with error as shown below.
24 filename mapfile '/GTU/dynamic.map';
25 filename testfile '/GTU/dynamic.xml';
26
27 libname xmlfile xml xmlmap=mapfile /*automap=replace*/;
NOTE: Libref XMLFILE was successfully assigned as follows:
Engine: XML
Physical Name:
28
29 proc copy in=xmlfile out=work;
30 run;
ERROR: Physical file does not exist, /GTU/dynamic.map.
encountered during XMLMap parsing
occurred at or near line 1, column 1
ERROR: XML describe error: Internal processing error.
Also please let me know how can I create the mapping file from Excel?
Sorry, you don't seem to understand. A map file is associated with an XML file, it is the map from XML to dataset.
This:
filename mapfile '/GTU/dynamic.map';
Does not exist, this is what you should be creating from XML mapper, it is the map between XML and dataset.
My other suggestion was that you open the XML file in Excel and use Excel to save the data to CSV - nothing to do with XML, maps or anything else.
Could you please help me understand on the next steps once I create the map file from SAS XML Mapper?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.