DATA Step, Macro, Functions and more

How to pull/generate an XML file?

Reply
Contributor jei
Contributor
Posts: 61

How to pull/generate an XML file?

[ Edited ]

Hi!

 

I would like to ask if SAS have a tool to pull an XML file automatically OR are there scripts that can pull the XML file?

 

Thank you!

Super User
Posts: 17,750

Re: How to pull an XML file?

What do you mean by 'pull an XML file'? Are you trying to read it into a dataset?

 

If so, try the XML Mapper tool. 

 

http://support.sas.com/documentation/cdl/en/engxml/64990/HTML/default/viewer.htm#n10gcahtsna7r7n1rbn...

Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

Hi @Reeza,

I already used an XML Mapper but what we want is to generate the XML file so that the data will update automatically
Super User
Posts: 17,750

Re: How to pull an XML file?

So you have an XML file that your adding to? Please explain in detail what your trying to do. The terminology isn't clear to me, but XML isn't my area. However, I have used SAS to both create and read XML file. 

Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

Okay,here's the scenario. The XML file is from the Cisco Prime API. What I am doing in order to get the XML file is by right clicking and then "save page as...".

 

Now, what I am askin' / want to know is if there's a way in SAS in order to automatically generate the XML file.

Super User
Posts: 17,750

Re: How to pull an XML file?

Ok. So you want to automatically reference an XML file generated by an API. There should be a URL or http method to access the data. 

See the links below, the second is probably closer to what you want. 

 

http://blogs.sas.com/content/sasdummy/2012/12/18/using-sas-to-access-data-stored-on-dropbox/

 

 

http://support.sas.com/documentation/cdl/en/engxml/64990/HTML/default/viewer.htm#n1d4p29qcfovrxn1k4n...

Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

Hi,

 

I followed the query

filename nhl url 'http://www.a.com/Nhl.xml';
filename map 'C:\My Documents\XML\Nhl.map';

libname nhl xml xmlmap=map;

proc copy indd=nhl outdd=work;
   select nhl;
run;

But the resulted data set has no rows as shown in the image below. Do you have any idea about it?

 

 

XML file resulted.JPG

Super User
Posts: 9,662

Re: How to pull an XML file?

If that is a HTML file , you don't need to transform it into XML , read HTML directly . Like :

 

filename x url 'http://www.sas.com';
data want;
 infile x recfm=n dlm='<>' ;
 input @'>' x : $2000. @@;
run;
Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

Hi!

I used this script and I successfully generate an xml file.

FILENAME outfile "C:\Users\jgmanalo\Desktop\Sample1\From URL\OutXML.xml";
LIBNAME source XML 'C:\Users\jgmanalo\Desktop\Sample1\From URL\outxml.xml';
PROC HTTP
 OUT = outfile
 URL = 'https://rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true'
 METHOD = 'GET';
RUN;

The XML file that I want is this

 

 

1.JPG

 

But what I'm only getting is this

 

1.JPG

 

Is there something wrong with the script?

Thank you!

 

 

 

 

 

 

 

 

 

 

Super User
Posts: 9,662

Re: How to pull an XML file?

Since you can download XML file, Try this code :

 

 

FILENAME outfile "C:\Users\jgmanalo\Desktop\Sample1\From URL\OutXML.xml";
LIBNAME source XML 'C:\Users\jgmanalo\Desktop\Sample1\From URL\outxml.xml';
PROC HTTP
 OUT = outfile
 URL = 'https://rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true'
 METHOD = 'GET';
RUN;


filename xx temp;
libname xx xmlv2 'C:\Users\jgmanalo\Desktop\Sample1\From URL\OutXML.xml'  automap=replace xmlmap=xx;
proc copy in=xx out=work;
run; 
Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

Hi,

I tried the code that you gave but an error occured

1.JPG

Super User
Posts: 9,662

Re: How to pull an XML file?

That is encoding problem. Maybe try this :

 

FILENAME outfile "C:\Users\jgmanalo\Desktop\Sample1\From URL\OutXML.xml" encoding='utf-8';

 

 


FILENAME outfile "C:\Users\jgmanalo\Desktop\Sample1\From URL\OutXML.xml" encoding='utf-16le';

Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

I try to add the UTF but still the error still the same
Super User
Posts: 9,662

Re: How to pull an XML file?

Could attach a sample file , so we can test it ?
Contributor jei
Contributor
Posts: 61

Re: How to pull an XML file?

This should be the content of dataset or the dataset should be look like the image below

1.JPG

 

But the URL is not accessible outside.

 

Ask a Question
Discussion stats
  • 28 replies
  • 466 views
  • 0 likes
  • 3 in conversation