Convert different XML files to a combined SAS dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Convert different XML files to a combined SAS dataset

Hi, 

I want to convert some xml files to a single sas dataset.

 

I am using the following code that I found on the internet somewhere, but I am getting an error called "XML describe error: XML table does not exist DETAIL."

 

options symbolgen;
libname outfile 'H:\test';
proc datasets lib=outfile kill; 
run;
quit;
%macro test(dir);
%let filerf=mydir;
%let rc=%sysfunc(filename(filerf,&dir)); 
%let did=%sysfunc(dopen(&filerf)); 
%let memcnt=%sysfunc(dnum(&did)); 
%let cnt=0;
%do i=1 %to &memcnt;
%let fname=%scan(%qsysfunc(dread(&did,&i)),1,’.’); 
%let cnt=%eval(&cnt+1);
%let name&cnt=&fname; 
%end;
filename SXLEMAP 'S:\program\case selection\iqi_xml_sfy2008.map'; 
%do i=1 %to &cnt; 
libname xml&i xml "&dir.\&&name&i...xml" xmlmap=sxlemap access=readonly;
proc datasets lib=xml&i; 
run;
proc append base=outfile.detail data= xml&i..detail force; 
run;
libname xml&i; 
clear;
%end;
%let rc=%sysfunc(dclose(&did)); 
%mend test;
%test(h:\xml temp);

Accepted Solutions
Solution
‎04-20-2018 07:54 AM
Super User
Super User
Posts: 9,599

Re: Convert different XML files to a combined SAS dataset

Posted in reply to katariasarthak

Well, there's not much to add to the error message:

XML describe error: XML table does not exist DETAIL.

 

The table DETAIL does not exist in the XML file.  I have nothing further to go on.

 

If I was you I would start by importing one XML file, with some simple datastep code.  Once you have that working, then look at doing it for several files, but until you get a single bit of code working nothing else will.  All you need to start is:

 

libname myxml xml "h:\xml temp\file1.xml" xmlmap=sxlemap access=readonly;
data want;
set myxml.detail; /* <-- note here it is stating detail */
run;

You will note that a table "detail" is to be looked for in the XML file (in your original code):

proc append base=outfile.detail data= xml&i..detail force; 
run;

I expect that you just copy and pasted that, but you need to replace detail with the table in your XML.

 

One you have that running then a simple loop around it and you can import multiple files.

 

 

 

 

 

 

 

View solution in original post


All Replies
Solution
‎04-20-2018 07:54 AM
Super User
Super User
Posts: 9,599

Re: Convert different XML files to a combined SAS dataset

Posted in reply to katariasarthak

Well, there's not much to add to the error message:

XML describe error: XML table does not exist DETAIL.

 

The table DETAIL does not exist in the XML file.  I have nothing further to go on.

 

If I was you I would start by importing one XML file, with some simple datastep code.  Once you have that working, then look at doing it for several files, but until you get a single bit of code working nothing else will.  All you need to start is:

 

libname myxml xml "h:\xml temp\file1.xml" xmlmap=sxlemap access=readonly;
data want;
set myxml.detail; /* <-- note here it is stating detail */
run;

You will note that a table "detail" is to be looked for in the XML file (in your original code):

proc append base=outfile.detail data= xml&i..detail force; 
run;

I expect that you just copy and pasted that, but you need to replace detail with the table in your XML.

 

One you have that running then a simple loop around it and you can import multiple files.

 

 

 

 

 

 

 

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 118 views
  • 0 likes
  • 2 in conversation