BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

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

 

ChrisNZ
Tourmaline | Level 20

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) 

 

Kurt_Bremser
Super User

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

mlogan
Lapis Lazuli | Level 10
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.
mlogan
Lapis Lazuli | Level 10
oh I got It! datafile should be datafile=test. Thanks.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 7467 views
  • 2 likes
  • 4 in conversation