Reputation: 461
How can I convert XML files to SAS dataset / Excel / CSV file using SAS
Upvotes: 2
Views: 6552
Reputation: 1
For XML->dataset can also do:
libname cata xml "path\name.xml";
data datasetname;
set cata.datasetname;
run;
Upvotes: 0
Reputation: 63424
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.
Upvotes: 1