BookmarkSubscribeRSS Feed
jei
Quartz | Level 8 jei
Quartz | Level 8

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!

28 REPLIES 28
Reeza
Super User

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...

jei
Quartz | Level 8 jei
Quartz | Level 8
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
Reeza
Super User

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. 

jei
Quartz | Level 8 jei
Quartz | Level 8

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.

Reeza
Super User

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...

jei
Quartz | Level 8 jei
Quartz | Level 8

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

Ksharp
Super User

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;
jei
Quartz | Level 8 jei
Quartz | Level 8

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!

 

 

 

 

 

 

 

 

 

 

Ksharp
Super User

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; 
jei
Quartz | Level 8 jei
Quartz | Level 8

Hi,

I tried the code that you gave but an error occured

1.JPG

Ksharp
Super User

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';

jei
Quartz | Level 8 jei
Quartz | Level 8
I try to add the UTF but still the error still the same
Ksharp
Super User
Could attach a sample file , so we can test it ?
jei
Quartz | Level 8 jei
Quartz | Level 8

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 28 replies
  • 1760 views
  • 0 likes
  • 3 in conversation