BookmarkSubscribeRSS Feed
msalam92
Calcite | Level 5
I have hundreds of XML files (all with same structure) that I want to read/write in SAS.

What is the most efficient way? I was thinking of adding in loops that iterates through the number of XML files and stops once all files are read. Can this be done?

Your feedback will be greatly appreciated.
Thank You.
15 REPLIES 15
PeterClemmensen
Tourmaline | Level 20

Do you want to read the files into separate SAS data sets or into a single data set since they all have the same structure?

msalam92
Calcite | Level 5
I want them all to be read into separate SAS datasets.
Reeza
Super User
Then it's a three step process.
1. Get a list of all files.
2.Write a program to read one file
3. Wrap it in a macro to read all files

If you show how you're reading one file, generalzing the other two is relatively easy. Do you know how to read one file?
msalam92
Calcite | Level 5
I do not, also where will the macros need to be created?

Apologies for the ignorance... SAS is brand new to me.
Thank You in advance.
Reeza
Super User
Maybe start there then, figure out how to read the file first. Then worry about how to do it for more than one. Macro's are programs, so you can store it wherever you're storing other programs.
msalam92
Calcite | Level 5

Ok, I was able to code for one XML and get it to read successfully. 

 

What is the next step? I am having a little tough time understanding. Am I just going to run the same code/ change file path 100 times?

 

Please suggest on how to move forward. 

Cynthia_sas
SAS Super FREQ
Hi:
Here is a paper that explains the basics of Macro Processing: https://support.sas.com/resources/papers/proceedings13/120-2013.pdf. It does not show using a Macro %DO loop, but once you get the basics out of the way, you can find examples on the forums of using CALL EXECUTE or a %DO loop to repeat a macro invocation multiple times.
Cynthia
msalam92
Calcite | Level 5
But the data is XML, not excel. Will the macro be created after the XML is generated into excel file?

Thanks for sharing Reeza.
Reeza
Super User
THose are examples of what you're trying to do, not the solution to your question. You can use it as an example of how to build your processes. Try walking through the tutorial, but if you have no SAS experience it may be kinda hard for you.

UCLA also has a good SAS Tutorial on macros.
msalam92
Calcite | Level 5

Here is the code I used to read one xml file. 

 

Any suggestions on how to continue adding other XMLs?

A loop? 

 

filename test1 url '.xml file path';
libname  test1 XML xml;

proc copy in=test out=work;
run;

proc print;
run

 

 

 
Reeza
Super User
Ok, next step, do you have a list of all the files you need to read in to a data set? Is there a systematic naming system to your xml files?

msalam92
Calcite | Level 5

Yes I have all the files. 

 

All the xml files are systematic. The URLs only change slightly based off the issue type. 

 

Ex: http://www.mysite.com/xml/testxml.xml 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 15 replies
  • 2850 views
  • 0 likes
  • 4 in conversation