How can I convert XML files to SAS dataset / Excel / CSV file using SAS
-
This is off topic because it is not really a statistical question. Check out this part of the FAQ: meta.stats.stackexchange.com/questions/793/…Peter Ellis– Peter Ellis2013-03-14 09:11:30 +00:00Commented Mar 14, 2013 at 9:11
-
I marked this for migration to StackOverflow but you might also try asking on SAS-L.Peter Flom– Peter Flom2013-03-14 11:12:40 +00:00Commented Mar 14, 2013 at 11:12
2 Answers
You need a lot more information than that, unfortunately, as "XML" file is a really really generic term, like "text file".
SAS will automatically import some XML files, if you have an XML map, or can create one, or the xml file's format is sufficiently obvious.
http://support.sas.com/documentation/cdl/en/engxml/62845/HTML/default/viewer.htm#a002484784.htm for more detail there.
Other XML files may be too difficult to read even with a map, particularly if they have extremely non-tabular layouts. For those it's usually easiest to use a data step and read it as a text file, and parse it on your own. Extremely oversimplified code for that:
data want;
infile "myfile.xml" lrecl=100 pad truncover;
input @1 curline $100.;
if substr(curline,1,7)='<mytag>' then do;
mytag = substr(curline,8,find('</',curline)-7);
end;
run;
That's obviously really messy; better is to use regular expressions to parse it out; either way it has to be highly customized for your xml file, since if it's not tabular obviously you will have to do some work. You can google some solutions if you have to go this route - but try the XML map first. If your installation included the SAS XML Map utility (a separate program), try running that; if not, see if your site administrator can install it for you.