Help using Base SAS procedures

How to create sas dataset from XML file (without using xml Engine )

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

How to create sas dataset from XML file (without using xml Engine )

Hi,

Is there any way we can create datasets from XML file without using XML engine? I don't have xml engine.

What is the easiest and best method to create sas datasets from xml file using base sas?


Accepted Solutions
Solution
‎12-14-2011 04:13 PM
Trusted Advisor
Posts: 1,301

How to create sas dataset from XML file (without using xml Engine )

It is not a licenced product, it is just part of Base SAS so you will not see it listed by proc setinit.

Try running this.

filename yt url 'http://gdata.youtube.com/feeds/api/videos/pzI4D6dyp_o/comments?v=2&max-results=50&start-index=1';

libname ytube xml xmlfileref=yt;

data ytube;

set ytube.entry;

run;

This is without defining a proper xml map for this feed so it is not perfect, just to show you that you can use xml engine.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,301

How to create sas dataset from XML file (without using xml Engine )

The XML LIBNAME Engine is a part of Base SAS since at least version 8.2

Contributor
Posts: 29

How to create sas dataset from XML file (without using xml Engine )

Really....I'm using SAS 9.1. I checked it by running proc setinit; run; I didn't see xml engine. 

How can i use the xml libname engine in base sas.

Thanks a ton for your quick responese.

Solution
‎12-14-2011 04:13 PM
Trusted Advisor
Posts: 1,301

How to create sas dataset from XML file (without using xml Engine )

It is not a licenced product, it is just part of Base SAS so you will not see it listed by proc setinit.

Try running this.

filename yt url 'http://gdata.youtube.com/feeds/api/videos/pzI4D6dyp_o/comments?v=2&max-results=50&start-index=1';

libname ytube xml xmlfileref=yt;

data ytube;

set ytube.entry;

run;

This is without defining a proper xml map for this feed so it is not perfect, just to show you that you can use xml engine.

SAS Super FREQ
Posts: 8,868

Re: How to create sas dataset from XML file (without using xml Engine )

Hi:

  Since the XML Libname Engine is part of Base SAS, you won't see it in PROC SETINIT. (you don't see PROC PRINT, FREQ or MEANS in SETINIT either, but you can still use them).

  OK...let's assume that you have an XML file stored in c:\temp\giftidea.xml (as shown in the attached screenshot). Then this code (in 9.2 or higher) would read the XML file into a SAS dataset:

** for 9.2;
/* libname giftxml xml92 'c:\temp\giftidea.xml';  */
  
 
** for 9.1.3;
libname giftxml xml 'c:\temp\giftidea.xml';
 
proc contents data=giftxml._all_;
run;
   
data mygifts;
   set giftxml.giftidea;
run;
 
proc print data=work.mygifts;
run;
  
libname giftxml clear;

  If your data are not in a simple structure, as defined in the doc for the Libname Engine, then you would have to use an XML Map file to map from more hierarchical XML to SAS dataset form.

cynthia


pix_giftidea_xml.jpg
🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 196 views
  • 3 likes
  • 3 in conversation