BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jei
Quartz | Level 8 jei
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
%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);

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
%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);

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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