简体   繁体   中英

How can I convert XML to SAS dataset / Excel / CSV file using SAS

如何使用SAS将XML文件转换为SAS数据集/ Excel / CSV文件

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.

For XML->dataset can also do:

libname cata xml "path\name.xml";

data datasetname;
set cata.datasetname;
run;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM