DATA Step, Macro, Functions and more

How to save a XML file in a local file using X statement

Reply
Contributor jei
Contributor
Posts: 74

How to save a XML file in a local file using X statement

Hi!

 

I'm using the code below to generate the XML file from API and I want to save it to C:\Users\Desktop\Sample1\From URL\curl\savedfile.xml as an xml file. But after the execution the windows explorer of the path just popping up and no file was created

 

May I know what is the best way to save the xml file in my computer?

Thank you!

x "curl -k https://root:Tr3nd512345@rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true > C:\Users\Desktop\Sample1\From URL\curl\savedfile.xml";

 

Super User
Super User
Posts: 7,977

Re: How to save a XML file in a local file using X statement

What happens when you run the command:

curl -k https://root:Tr3nd512345@rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true > C:\Users\Desktop\Sample1\From URL\curl\savedfile.xml

From the command prompt?  Its likely you, or the place where SAS is installed is missing a permission, or the location.  You can try:

filename tmp pipe 'curl -k https://root:Tr3nd512345@rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true > C:\Users\Desktop\Sample1\From URL\curl\savedfile.xml';

data test;
  length buff $2000;
  infile tmp dlm="¬";
  input buff $;
run;
  

That should get the messages back from the system.  Maybe there is no path like that on C: (which is where SAS is installed not necessarily your local machine) or maybe you (or the SAS install) doesn't have permission to access that https site.

Contributor jei
Contributor
Posts: 74

Re: How to save a XML file in a local file using X statement

Hi @RW9,

 

When using the X statement, the command shows the exact details of the XML file. That is, we have a peermission to access the https. Do you know where I can check the SAS missing permission that you are saying? 

 

Also, the log resulted 0 obs using the filename pipe as the image shows.Capture.JPG

Super User
Super User
Posts: 7,977

Re: How to save a XML file in a local file using X statement

I would check with your IT group.  It sounds like SAS is installed on a network, and may need to be given the same permissions as your local machine.  

Contributor jei
Contributor
Posts: 74

Re: How to save a XML file in a local file using X statement

SAS was installed only on my local computer and have an Administration account.
Super User
Super User
Posts: 7,977

Re: How to save a XML file in a local file using X statement

Two other things you could try - turn xwait on:

options xwait;

Any OS window that opens will not close automatically, so you may see further information.  Also try running it from %sysexec:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000171045.htm

 

And just to check again, if you goto the OS window, and run that command it does work?  It just seems strange as SAS local would just push the text out to the OS to run, so it should be exactly the same.

Also, you have spaces inside the path (never recommended!) so you might need to quote the path (i have quoted both the https and path, try either if that doesn't work):

x 'curl -k "https://root:Tr3nd512345@rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true" > "C:\Users\Desktop\Sample1\From URL\curl\savedfile.xml"';

 

Super User
Posts: 10,041

Re: How to save a XML file in a local file using X statement

If you could run

 

x "curl -k https://root:Tr3nd512345@rbc-svr-pi/webacs/api/v1/data/ClientDetails?.full=true > want.xml";

 

then  WANT.XML should be under the same  folder/directory with curl.exe , Check Where CURL is installed .

Ask a Question
Discussion stats
  • 6 replies
  • 283 views
  • 0 likes
  • 3 in conversation