Desktop productivity for business analysts and programmers

Help with XML output from SAS

Reply
Occasional Contributor
Posts: 12

Help with XML output from SAS

I am trying to output the data into XML. I am using the code
which is in the attached XML code.docxsas. I get the output as shown in the
attached Tstg.txt. Actually, I copied the output from browser and pasted in the
txt file. But I actually need the output as shown in Tstg-expected.txt file. I
am using 'SAS ENTERPRISE GUIDE 5.1'. Here are the issues:

  1. I am not able to insert the data, which says Level1 in
    the code into the mainlevelsubmission which is the top level in the XML output.
  2. I am unable to create and output variable called 'Record'
    with a sequential value(1,2,3..) in all the levels except the
    mainlevelsubmission in the output as shown in tstg-expected file.
  3. I do not need that repeated 'includedcompany' and
    'includedMember' level in the output except for a distinct 'COMP_ID' and 'IDS'
    value respectively.

For eg: In the tstg.txt file there is repeated level for
'includedcompany' with the same COMP_ID value '10000', but I need only those
distinct 'includedcompany' levels with COMP_ID value '10000' and '20000' (you
can see this in the tstg-expected.txt file)

Similarly, there is a repeating level of 'includedmember'
for the same IDS value of '1234567' in the tstg.txt file, which I do not need in
the output either.

4.I also need to output the labels of variables in the
output rather than variable names, I want to do this because there are some
variable names whose length is greater than 32, for eg
'TotalcountOfPeriodsForIncludedMembers'. I cannot output this name as column
name so I use it as a label instead and trying to output it.

well, I have a template for this to output the labels of
variables in XML output instead of names. Here it is

proc template;

define tagset tagsets.uselabs;

parent=tagsets.sasxmog;

NOTES "USE LABEL INSTEAD OF NAME FOR TAGS";

DEFINE EVENT SASCOLUMN;

start:

ndent;

put '<';

put TEXT / if cmp(XMLDATAFORM, "ATTRIBUTE");

put ' name="' / if cmp(XMLDATAFORM,
"ATTRIBUTE");

put LABEL;

put '"' / if cmp(XMLDATAFORM, "ATTRIBUTE");

break;

finish:

xdent / if exist (MISSING);

break / if exist(MISSING);

put ' / >' / if cmp(XMLDATAFORM, "ATTRIBUTE");

put CR / if cmp(XMLDATAFORM, "ATTRIBUTE");

xdent / if cmp(XMLDATAFORM, "ATTRIBUTE");

break / if cmp(XMLDATAFORM, "ATTRIBUTE");

put '</';

put label;

put '>';

put CR;

xdent;

break;

end;

end;

run;

But,  I cannot use this template above and the other one which is in the attached code at once. I
can only use either of them. So best I could do it is to insert this tagset
above into the already existing template 'tagsets.custom' which is in the
attached XML code sas. I have no idea how to do that as I am not an expert in
writing customized tagsets.

5. And finally I need that ns1: to go in the tag like '<ns1:includedMemberPeriods>'
in my output. When I tried to do that the code doesn't show any error but the
output says

The operation completed successfully. Error processing
resource 'file:///C:/Tstg.XML'...

<ns1:MainLevelSubmission>

6.  "Note: SAS variable labels, formats, and lengths are not written to DBMS tables."

This note appears in the log, how can I write SAS variable labels, formats, and lengths into DBMS tables?

So if somebody could help me out in resolving these issue or any ideas in doing so are highly appreciated

Thank you.

Attachment
Attachment
Attachment
SAS Super FREQ
Posts: 8,819

Re: Help with XML output from SAS

Hi:

Do you have a schema for the valid XML that you need to generate? It looks like you are using the XML Libname Engine? The code that you attached looks like the type of template you might need to write back in SAS 9.1 -- before the XML Libname engine could use a schema with the XML Mapper to make you a map file. So, depending on the version of SAS you have, you might not need a custom tagset template. If so, the XML might be able to be generated using the standard XML Libname engine and an XML Map file. You are correct that you can only use one tagset template at a time in one ODS invocation statement or XML LIBNAME engine statement.

  Have you looked at or tried to use the XML Mapper tool?

  My recommendation is that you open a track with Tech Support. There are a lot of factors involved in generating your custom XML.

cynthia

Occasional Contributor
Posts: 12

Re: Help with XML output from SAS

Hey Cynthia,

It's been a while on this post. Thank you very much on your feedback. I've generated the desired XML file by writing the customized template. Though I 've the XSDs provided on this, I did not use them at all. Can you tell me how is it different generating a XML file using the tagset and the XSD schema, when the XML file generated still follows the desired structure and datatype. Is it necessary to use the XSD files.

Please advice.

SAS Super FREQ
Posts: 8,819

Re: Help with XML output from SAS

Hi:

  If you do have an XSD file and you are using SAS 9.2 or higher, the XML Libname Engine can read the XSD file and generate the appropriate map file to both import and export to/from XML. In SAS 9.1.3, when you needed to export from SAS to an XML format, there was no way for the XML Mapper to read the XSD file, and so you needed to write your own template to generate the tags with the proper structure. The purpose of an XSD file is to provide the structure information to the application that is going to read (or write) the XML file. In SAS 9.1.3, the XML Mapper read the XML and built a map file. Starting with SAS 9.2, the XML Mapper application could read either an XML file or an XSD file to build the map.

  There is no absolute answer to your question. It is not necessary to use the XSD file. But it might be easier if you did. It is up to you.

cynthia

Occasional Contributor
Posts: 12

Re: Help with XML output from SAS

Hi Cynthia,

Your response is very helpful. I tried using the XML libname engine to create a map file from the XSD I have in order to generate a XML file. But the map file looks very weird, it didn't read the column names I need in XML. Please find the attached XSD (File1) and the created map file (MapICr). I am also attaching my sample XML file(expectedFile) required to be generated. I am on SAS 9.4. Please help me out on why map looks different and what needs to be done to resolve the issue.

Thank you.

Attachment
Attachment
SAS Super FREQ
Posts: 8,819

Re: Help with XML output from SAS

Hi, Jessy:

  I am teaching and unable to do much more than post programs that have already been written or answer quick questions. If you need help with a specific problem, opening a track with Tech Support would be better, as they can refer your question to someone who is familiar with the XML Mapper in SAS 9.4.

cynthia

Occasional Contributor
Posts: 12

Re: Help with XML output from SAS

No problem Cynthia. Thank you very much.

Ask a Question
Discussion stats
  • 6 replies
  • 720 views
  • 9 likes
  • 2 in conversation