Hello,
I have hundreds of xml files to import, all of them with the same layout. I have made the xml map with SAS XML mapper and used code from user called dapstat to import multiple files but it does not read the data eventhough I get a list of the files in the directory.
Could someone please help me in case dapstat is not available? I have already contacted him through his original post. I attach the log.
Or maybe there is a different way?
Thank you in advance.
filename SXLELIB '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\sgfxml\02303_20171016070200.xml';
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SGFXML\siammapV2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY;
DATA alerta; SET SXLELIB.alerta; run;
libname siamia 'C:\Users\SAS\Desktop\siamia';
filename DIRLIST pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\sgfxml\0*.xml" /b';
data dirlist ;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;
data _null_;
set dirlist end=end;
count+1;
call symputx('read'||put(count,4.-l),cats("\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\",file_name));
call symputx('dset'||put(count,4.-l),scan(file_name,1,'.'));
if end then call symputx('max',count);
run;
data siamia.dirlist(rename=(file_name=leadfile));
set dirlist;
order=_n_;run;
options mprint symbolgen;
%macro readin;
%do i=1 %to &max;
data siamia.leadtarget&i;
set siamia.dirlist;
if &i=order;
run;
proc sql noprint;
select leadfile
into :lf
from siamia.leadtarget&i;
quit;
filename sgfxml "C:\Users\SAS\Desktop\siamia\&lf";
filename map "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SGFXML\siammapV2.map";
libname sgfxml xmlv2 xmlmap=map;
data siamia.lead;
set siamia.lead;
run;
%end;
%mend readin;
%readin;
Could you use the following code to import XML automatically ,not need offer XML map.
filename x temp;
libname SXLELIB xmlv2 'c:\temp\temp.xml' xmlmap=x automap=replace;
proc copy in=SXLELIB out=work ;
run;
Hi, thanks for your reply, but this is only for one file, right?
I need to import hundreds into 1 single sas dataset. thanks
Well to start with you seem to have a network patch for the map:
"\\tsclient\C\Transferencia de Archivos\IMPORT | |
22 ! TO SAS\SIAM\ |
And yet refer to a local c drive for the file:
filename sgfxml "C:\Users\SAS\Desktop\siamia\&lf";
To be honest though your code is so hard to read, consider simplifying it:
/* These dont change */ filename SXLELIB '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\sgfxml\02303_20171016070200.xml'; filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SGFXML\siammapV2.map'; libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY; /* Macro to read in data */ %macro importfile (fn=,ds=); filename sgfxml "..."; filename map "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SGFXML\siammapV2.map"; libname sgfxml xmlv2 xmlmap=map; data siamia.lead; set siamia.lead; run; %mend importfile; filename DIRLIST pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\sgfxml\0*.xml" /b'; data _null_; infile dirlist lrecl=200 truncover dlm="¬"; input; call execute(cats('%importfile (fn=',_input_,',ds=',scan(_input_,1,"."),');')); run;
Thanks, but both are correct, it doesn´t make any diference.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.