I have a map that works with my xml files and I managed to process all of them with xmlmap and get all proc contents for them but I can't view the datasets in sas to start working with the data. I attach one of the xml files as an example . Could someone please help? Thanks in advance.
filename SXLELIB '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\02303_20171015132340.xml';
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\siammapV2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY;
/*
* Catalog
*/
proc datasets lib=SXLELIB; run;
/*
* Contents
*/
proc contents data=SXLELIB.alerta varnum; run;
* Printing
*/
title 'Table alerta';
proc print data=SXLELIB.alerta; run;
title;
/*
* Local Extraction
*/
DATA alerta; SET SXLELIB.alerta; run;
filename prueba pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\siam\*.xml" /b';
data file_list;
length fname $20;
infile prueba truncover; /* infile statement for file names */
input fname $20.; /* read the file names from the directory */
call symput ('num_files',_n_); /* store the record number in a macro variable */
run;
%macro fileread;
%do j=1 %to &num_files;
data _null_;
set file_list;
if _n_=&j;
call symput ('filein',fname);
run;
filename SXLELIB "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\&filein..xml";
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\siammapV2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY;
proc datasets lib=SXLELIB; run;
proc contents data=sxlelib._all_ varnum; run;
%end; /* end of do-loop with index j */
%mend fileread;
%fileread;
proc copy in=sxlelib out=work;
run;
GOT IT! Partly thanks to "A Macro for Reading Multiple Text Files" by Debbie Miller, National Park Service, Denver, CO " and user Reeza who made a question that made me think about one piece of my code.
/*libname root created by xml mapper*/
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY;
/*create macro to read all file names in folder*/
filename prueba pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\siam\*.xml" /b';
data file_list;
length fname $20;
infile prueba truncover; /* infile statement for file names */
input fname $20.; /* read the file names from the directory */
call symput ('num_files',_n_); /* store the record number in a macro variable */
run;
%macro fileread;
%do j=1 %to &num_files;
data _null_;
set file_list;
if _n_=&j;
call symput ('filein',fname);
run;
/*code to retrieve xml map created*/
filename SXLELIB "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\&filein..xml";
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\siammapv2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY ;
proc datasets lib=SXLELIB; run;
proc contents data=sxlelib._all_ varnum; run;
/*copy sxlelib to your library*/
proc copy in=sxlelib out=work;
run;
/*save each file read named 'alerta' as in xml mapper in a single sas dataset call data_all*/
%if &j=1 %then %do;
data data_all;
set alerta;
run;
%end;
%else %do;
data data_all;
set data_all
alerta;
run;
%end;
%end;
%mend fileread;
%fileread;
> I can't view the datasets in sas to start working with the data.
What does that mean? Post your log instead.
Thanks for your interest. I'm trying with 4 xml files but have hundreds to import.
I also attach the output. Thanks.
Forget the macro for now, do you have a process to read a single file working and imported data.
I don't actually see any steps (PROC COPY?) where you try to store the data...the first attempt seems to work fine but it's hard to follow. I won't have time to test anything until later but wanted to make sure I understand where you're currently at.
Ok, now because of your question I realised I placed proc copy outside the macro so I changed my code and now I can see one resulting dataset in work library, but only one, the last file generated. I supose that's because they all get the same name 'alerta' given in sas xml mapper application and the next dataset overwrites the previous one.. how can I change that and see all of them? Your help is being much appreciated.
filename prueba pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\siam\*.xml" /b';
data file_list;
length fname $20;
infile prueba truncover; /* infile statement for file names */
input fname $20.; /* read the file names from the directory */
call symput ('num_files',_n_); /* store the record number in a macro variable */
run;
%macro fileread;
%do j=1 %to &num_files;
data _null_;
set file_list;
if _n_=&j;
call symput ('filein',fname);
run;
filename SXLELIB "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\&filein..xml";
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\siammapV2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP ;
proc datasets lib=SXLELIB; run;
proc contents data=sxlelib._all_ varnum; run;
proc copy in=sxlelib out=work;
run;
%end; /* end of do-loop with index j */
%mend fileread;
%fileread;
GOT IT! Partly thanks to "A Macro for Reading Multiple Text Files" by Debbie Miller, National Park Service, Denver, CO " and user Reeza who made a question that made me think about one piece of my code.
/*libname root created by xml mapper*/
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY;
/*create macro to read all file names in folder*/
filename prueba pipe 'dir "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\siam\*.xml" /b';
data file_list;
length fname $20;
infile prueba truncover; /* infile statement for file names */
input fname $20.; /* read the file names from the directory */
call symput ('num_files',_n_); /* store the record number in a macro variable */
run;
%macro fileread;
%do j=1 %to &num_files;
data _null_;
set file_list;
if _n_=&j;
call symput ('filein',fname);
run;
/*code to retrieve xml map created*/
filename SXLELIB "\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\&filein..xml";
filename SXLEMAP '\\tsclient\C\Transferencia de Archivos\IMPORT TO SAS\SIAM\siammapv2.map';
libname SXLELIB xmlv2 xmlmap=SXLEMAP access=READONLY ;
proc datasets lib=SXLELIB; run;
proc contents data=sxlelib._all_ varnum; run;
/*copy sxlelib to your library*/
proc copy in=sxlelib out=work;
run;
/*save each file read named 'alerta' as in xml mapper in a single sas dataset call data_all*/
%if &j=1 %then %do;
data data_all;
set alerta;
run;
%end;
%else %do;
data data_all;
set data_all
alerta;
run;
%end;
%end;
%mend fileread;
%fileread;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.