DATA Step, Macro, Functions and more

Using MACRO DO LOOP to convert each XML file into dataset

Accepted Solution Solved
Reply
Contributor jei
Contributor
Posts: 61
Accepted Solution

Using MACRO DO LOOP to convert each XML file into dataset

Hi,

I have multiple XML file, file1.xml, file2.xml, file3.xml. I want to convert each XML file into SAS dataset using macro do loop.

I have the following syntax to convert XML file into SAS dataset but I don't know how to use the %do loop to this script. 

filename  File 'C:\Users\Desktop\XML Files\File1.xml';
filename  SXLEMAP 'C:\Users\DesktopC:\Users\Desktop\XML Files\File1.map';
libname  File xmlv2 xmlmap=SXLEMAP access=READONLY;

/*
 *  Catalog
 */

proc datasets lib= File; run;

/*
 *  Contents
 */

proc contents data= File.queryResponse varnum; run;


/*
 *  Printing
 */

title 'Table queryResponse';
proc print data= File.queryResponse; run;
title;

/*
 *  Local Extraction
 */

DATA  file; SET  File.queryResponse; run;

Appreciating your help.

Thanks!


Accepted Solutions
Solution
‎07-01-2016 04:20 AM
Super User
Posts: 6,971

Re: Using MACRO DO LOOP to convert each XML file into dataset

%macro do_what_you_want(startnum,endnum);
%do i = &startnum %to &endnum;
filename  file "C:\Users\Desktop\XML Files\File&i..xml";
filename  SXLEMAP "C:\Users\DesktopC:\Users\Desktop\XML Files\File&i..map";
libname  file xmlv2 xmlmap=SXLEMAP access=READONLY;

proc datasets lib=file;
run;

proc contents data=file.queryresponse varnum;
run;

title "Table queryResponse from File File&i..xml";

proc print data=file.queryresponse;
run;

title;

data file&i;
set file.queryresponse;
run;
%end;
%mend;
%do_what_you_want(1,3);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎07-01-2016 04:20 AM
Super User
Posts: 6,971

Re: Using MACRO DO LOOP to convert each XML file into dataset

%macro do_what_you_want(startnum,endnum);
%do i = &startnum %to &endnum;
filename  file "C:\Users\Desktop\XML Files\File&i..xml";
filename  SXLEMAP "C:\Users\DesktopC:\Users\Desktop\XML Files\File&i..map";
libname  file xmlv2 xmlmap=SXLEMAP access=READONLY;

proc datasets lib=file;
run;

proc contents data=file.queryresponse varnum;
run;

title "Table queryResponse from File File&i..xml";

proc print data=file.queryresponse;
run;

title;

data file&i;
set file.queryresponse;
run;
%end;
%mend;
%do_what_you_want(1,3);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor jei
Contributor
Posts: 61

Re: Using MACRO DO LOOP to convert each XML file into dataset

Thanks a lot!
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 245 views
  • 1 like
  • 2 in conversation