DATA Step, Macro, Functions and more

can't view sas data sets from xml files

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

can't view sas data sets from xml files

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;

  


Accepted Solutions
Solution
a week ago
Contributor
Posts: 20

IMPORT MULTIPLE XML FILES to ONE SAS DATASET USING XML MAPPER TO CREATE THE XML MAP

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; 

View solution in original post


All Replies
Super User
Posts: 19,822

Re: can't view sas data sets from xml files

> I can't view the datasets in sas to start working with the data.

 

What does that mean? Post your log instead.

Contributor
Posts: 20

Re: can't view sas data sets from xml files

Thanks for your interest. I'm trying with 4 xml files but have hundreds to import.

Contributor
Posts: 20

Re: can't view sas data sets from xml files

I also attach the output. Thanks.

Super User
Posts: 19,822

Re: can't view sas data sets from xml files

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.

Contributor
Posts: 20

Re: can't view sas data sets from xml files

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; 

 

Solution
a week ago
Contributor
Posts: 20

IMPORT MULTIPLE XML FILES to ONE SAS DATASET USING XML MAPPER TO CREATE THE XML MAP

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; 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 93 views
  • 0 likes
  • 2 in conversation