BookmarkSubscribeRSS Feed
pbrookha
Calcite | Level 5

I am having a difficult time figuring out how to export a SAS dataset into a specific directory on an sfs site. I am currently attempting to use filename ftp logic but am unsuccessful.

Does anyone have an example of successful logic?

 

Thanks

5 REPLIES 5
ballardw
Super User

Can you share the code and messages from the log for an attempt? XXXX out such sensitive things as user and password, if used.

 

"Unsuccessful" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

You may want to just use an X command or an operating system command to send things using your FTP program and a FILENAME has a bit more overhead involved than just sending a file.

pbrookha
Calcite | Level 5
%let mywk=%sysfunc(getoption(WORK));
%let target_folder=/###/####/; 
%let source_folder=/sas/shared/#####/;
%let source=ARRIVALS.xls; 

data _null_;
            file "&mywk/get_aff.cmd";
            put "user #####";
            put "cd &target_folder." ;
            put "lcd &source_folder" ;
            put "put &source.";
            put "ls -l";
            put "quit";

filename doftp pipe "sftp  -v  sfs.company.com  < &mywk/get_aff.cmd";
;
run;

The corresponding log if here:

 

NOTE: <<< 230 User ###### logged in.
NOTE: >>> OPTS UTF8 ON
NOTE: <<< 200 OPTS command successful
NOTE: >>> OPTS UTF8 NLST
NOTE: <<< 501 OPTS: parameters are incorrect
NOTE: >>> OPTS UTF-8 NLST
NOTE: <<< 501 OPTS: parameters are incorrect
NOTE: >>> PASV
NOTE: <<< 227 Entering Passive Mode (######)
NOTE: >>> TYPE A
NOTE: <<< 200 TYPE command successful
NOTE: >>> CWD /Distribution/WVR_Associate_Sites/OVI
NOTE: <<< 250 CWD command successful
NOTE: >>> PWD
NOTE: <<< 257 "/####/#####/" is current directory
NOTE: >>> PBSZ 0
NOTE: <<< 200 PBSZ command successful
NOTE: >>> PROT P
NOTE: <<< 200 PROT command successful
NOTE: >>> RETR /sas/shared/####/ARRIVALS.xls
NOTE: <<< 550 RETR failed: File could not be found
ERROR: Physical file does not exist, /sas/shared/####/ARRIVALS.xls.

pbrookha
Calcite | Level 5
filename Table ftp '/sas/shared/#####/ARRIVALS.xls' new cd=&directory 
user="#####" pass="#####" host=&host AUTHTLS recfm=v debug passive; 

data WORK.ARRIVALS;
infile Table truncover;
input filename $char1000.;
put _infile_;
run;
quit;

I have also tried this code after reading up on some forums from SAS and this ran successful but did not produce any results or log notes.

Kurt_Bremser
Super User

This data step

data WORK.ARRIVALS;
infile Table truncover;
input filename $char1000.;
put _infile_;
run;

tries to read data from the ftp file reference, store it in variable filename in dataset arrivals, and also writes the contents of each input line to the SAS log.

Since fileref table refers to an Excel file, this won't do you any good, since Excel files are not text files.

ballardw
Super User

@pbrookha wrote:
%let mywk=%sysfunc(getoption(WORK));
%let target_folder=/###/####/; 
%let source_folder=/sas/shared/#####/;
%let source=ARRIVALS.xls; 

data _null_;
            file "&mywk/get_aff.cmd";
            put "user #####";
            put "cd &target_folder." ;
            put "lcd &source_folder" ;
            put "put &source.";
            put "ls -l";
            put "quit";

filename doftp pipe "sftp  -v  sfs.company.com  < &mywk/get_aff.cmd";
;
run;

The corresponding log if here:

 

NOTE: <<< 230 User ###### logged in.
NOTE: >>> OPTS UTF8 ON
NOTE: <<< 200 OPTS command successful
NOTE: >>> OPTS UTF8 NLST
NOTE: <<< 501 OPTS: parameters are incorrect
NOTE: >>> OPTS UTF-8 NLST
NOTE: <<< 501 OPTS: parameters are incorrect
NOTE: >>> PASV
NOTE: <<< 227 Entering Passive Mode (######)
NOTE: >>> TYPE A
NOTE: <<< 200 TYPE command successful
NOTE: >>> CWD /Distribution/WVR_Associate_Sites/OVI
NOTE: <<< 250 CWD command successful
NOTE: >>> PWD
NOTE: <<< 257 "/####/#####/" is current directory
NOTE: >>> PBSZ 0
NOTE: <<< 200 PBSZ command successful
NOTE: >>> PROT P
NOTE: <<< 200 PROT command successful
NOTE: >>> RETR /sas/shared/####/ARRIVALS.xls
NOTE: <<< 550 RETR failed: File could not be found
ERROR: Physical file does not exist, /sas/shared/####/ARRIVALS.xls.


That line in red is pretty much it.

I would suggest that your SOURCE_FOLDER macro variable should be a fully qualified path from a disk mount point. The default starting with /sas/ probably meant the FTP program was using its default execution location and that does not have a subfolder named /sas/.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1144 views
  • 0 likes
  • 3 in conversation