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