DATA Step, Macro, Functions and more

Download files from FTP site to SAS

Accepted Solution Solved
Reply
Regular Contributor
Posts: 215
Accepted Solution

Download files from FTP site to SAS

Hi All,

I am trying to copy files from the FTP server to SAS. Can someone please help. Folowing the are code that I wrote. Thanks. 

 

 

FILENAME TEST FTP 'Test.xlsx' lrecl=256
                CD='/44434/Data/'
                HOST='files1.abc.com'
                USER='anonymous'
                PASS='XXXX';
				RUN;
PROC PRINT DATA=Test;
RUN;

Accepted Solutions
Solution
‎05-03-2017 09:12 PM
Super User
Posts: 6,928

Re: Download files from FTP site to SAS

The filename statement only creates a reference to the external file, it does not do anything on its own.

 

proc print only works for SAS datasets, not for external files. So you need to import the data from the xlsx into a SAS dataset first.

 

If have no idea if that could be possible in a single step. If it is possible at all, you need to define the file reference in a way that it works with the binary data of xlsx (xlsx is a zip archive of XML files; this means that the file itself is unstructured and must be handled as a stream).

 

So you might try

filename test ftp
  'Test.xlsx'
  cd='/44434/Data/'
  host='files1.abc.com'
  user='anonymous'
  pass='XXXX'
  recfm = s /* this is crucial */
;

proc import datafile=test dbms=xlsx out=work.test replace;
run;

But I'd separate the steps first, as @ChrisNZ suggested. You can even do a binary transfer in SAS alone, see http://support.sas.com/kb/43/962.html

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
PROC Star
Posts: 7,358

Re: Download files from FTP site to SAS

You need to create a datastep to input the file. For an example see: http://support.sas.com/kb/43/962.html

 

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 1,558

Re: Download files from FTP site to SAS

You need 2 steps before your proc print.

1- transfer the file to your machine, using the BINARY TRANSFER (read) logic in @art297 's link

2- proc import the transfered file into a SAS data set (or create a library with the xlsx engine) 

 

Solution
‎05-03-2017 09:12 PM
Super User
Posts: 6,928

Re: Download files from FTP site to SAS

The filename statement only creates a reference to the external file, it does not do anything on its own.

 

proc print only works for SAS datasets, not for external files. So you need to import the data from the xlsx into a SAS dataset first.

 

If have no idea if that could be possible in a single step. If it is possible at all, you need to define the file reference in a way that it works with the binary data of xlsx (xlsx is a zip archive of XML files; this means that the file itself is unstructured and must be handled as a stream).

 

So you might try

filename test ftp
  'Test.xlsx'
  cd='/44434/Data/'
  host='files1.abc.com'
  user='anonymous'
  pass='XXXX'
  recfm = s /* this is crucial */
;

proc import datafile=test dbms=xlsx out=work.test replace;
run;

But I'd separate the steps first, as @ChrisNZ suggested. You can even do a binary transfer in SAS alone, see http://support.sas.com/kb/43/962.html

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 215

Re: Download files from FTP site to SAS

Hi KurtBremser, Thanks for the explanation. In the proc import stage I don't have my file in work library (you mentioned datafile=test). My data file is at ftp server. What would be the datafile location in my case would you please explain. Thanks.
Regular Contributor
Posts: 215

Re: Download files from FTP site to SAS

oh I got It! datafile should be datafile=test. Thanks.
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 285 views
  • 2 likes
  • 4 in conversation