BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I have found few papers on how to read an xml file with the help of an XSD file in order to produce a SAS dataset.

 

The task, I am ask for is the opposite.

So we start by reading a SAS dataset, then convert this dataset into an xml file with the help of an XSD file (XML Schema definition) to make sure that the obtained xml file respect the expected structure. I am using SAS EG 7.11

 

I am not sure that XML mapper can be used to carry out this task.

 

Does anyone have already done this task and if so how?

 

Regards,

 

ALP

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Here's an example that shows exporting XML to a data set and creating an XSD:

 

Exporting an XML Document with Separate Metadata

 

Unfortunately, that creates the XSD, doesn't use an existing XSD as an output schema.  I think the only way to work this is the method you already discovered: import the XSD into XML Mapper to create an XML map, then export using the map as the structure.

 

You would need to install XML Mapper.  It's part of SAS Base, but I think you'll have to install from your software depot -- it's not a separate download.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

7 REPLIES 7
ChrisHemedinger
Community Manager

In SAS 9.4 you can use the XMLSCHEMA= option to reference an XSD, documented in the User's Guide.

 

Also, see this paper from @chrisschachererThe SAS Programmer's Guide to XML and Web Services

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
alepage
Barite | Level 11

Hello Chris,

 

I have already read your paper and what I have understood is that we can use XML Mapper and an XSD file to convert an XML file into a dataset.

 

What I am Interested in is the opposite situation:  Use the information provided from a XML Schema Definition file as well as the one from a SAS Dataset to produce an XML file with the structure corresponding to the information provided into the XSD.

 

Can we do that in SAS EG 7.11 and if so How.

As I am not familiar at all with the XML file , could you please provide me a short example? Do I need Absolutely the XML Mapper Add-on

Regards,

 

alepage
Barite | Level 11

I have already try this code below.  What I have understood, is that it take the SAS dataset and generate two files:

a) the XML file

b) the corresponding xsd FILE.

 

It is not what I would like to do.

The SAS data set and the XSD file are provided.

I want to use those information to write an XML file in compliance with the XSD provided file.

 

Again, based on your expertise, it is possible to do that and if so How.

Regards,

 

 

 

 

 

 

 

 

 

filename myxsd 'C:\Output\snacks.xsd'; /*1*/

 

libname output xmlv2 'C:\Output\snacks.xml'

xmlmeta=schemadata xmlschema=myxsd; /*2*/

data output.snacks; /*3*/

 

set sashelp.

 

alepage
Barite | Level 11
Hello Chris
Did you have a chance to look to my last post?
I Still need help...
ChrisHemedinger
Community Manager

Here's an example that shows exporting XML to a data set and creating an XSD:

 

Exporting an XML Document with Separate Metadata

 

Unfortunately, that creates the XSD, doesn't use an existing XSD as an output schema.  I think the only way to work this is the method you already discovered: import the XSD into XML Mapper to create an XML map, then export using the map as the structure.

 

You would need to install XML Mapper.  It's part of SAS Base, but I think you'll have to install from your software depot -- it's not a separate download.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
alepage
Barite | Level 11

Hello Chris,

 

At the beginning, I though that my approach was the gone one but after some discussions with my team members, the objectives are clearer.

 

An XML Schema Definition file is written where some criteria regarding the table to be evaluated (SAS table or XML File) must met .

 

For example, imagine in Table A (provided by another service), variable sex, obs=122 is missing.  IF the fact that this observation is missing in not critical based on the criteria of the XSD file the we accept the dataset otherwise an error report must be written who contains all the information for the observation # 122.

 

Same thing imagine in this Table A, based on the XSD file that var10 should be numeric and contains 9 number like a phone number, and for some reason we don't know, observation 425, contains only 6 number.   Then this observation should be added to the error report with observation 122, and so on.

 

At the end, if the sas table is error free based on the XSD file, then we go to the next step the transformation to the XML type.

Otherwise, a sas table is provided containing all the observations (complete line) who contains errors.

 

I hope with those clarifications you will be able to direct me toward a nice solution.

Regards,

 

 

 

ChrisHemedinger
Community Manager

It sounds like the XSD is not really a schema, but a set of business/validation rules.  Is that right?  And you need to have SAS code that "accepts" field values based on the rules/integrity constraints defined in this XSD?

 

I don't think the XML engine will help with the validation.  I'm sure it would be possible to read the XSD and generate the rules in DATA step, but depending on how many variations of rules you have, it could be a lot of work.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 4148 views
  • 0 likes
  • 2 in conversation