BookmarkSubscribeRSS Feed
Shahrukhh_Khan
Fluorite | Level 6

Hi All,

 

I need to transfer some files from SFTP server to SAS server on daily basis based on the SFTP date and time.

For example i need to transfer all the files for date 14th May or 17th May.

 

Can someone please help how i can access the SFTP date time from SAS.

 

With "mget" i can pull all the file available in SFTP but i want to pull the file only for the specific day.

 

6 REPLIES 6
JasonDiVirgilio
Quartz | Level 8

You should be able to use the DIR option to get a listing of files in the folder. You could then parse that listing to determine which files have the dates you want and "get" them by name.

 

https://documentation.sas.com/?docsetId=lestmtsglobal&docsetTarget=p0xln1fiwsr340n1xxf4mkmfxp6f.htm&...

 

 
Shahrukhh_Khan
Fluorite | Level 6
Thanks Jason for your reply.

I am not familiar with unix command.

Could you please give sample code related to DIR command so that i can relate it to my code and fetch the file name from SFTP server based on the date.

Thanks in Advance.
Patrick
Opal | Level 21

Before you even start using SAS get your SFTP command right to only select the files you're after. There will be a lot of examples when Googling the moment you take SAS out of the picture.

Once you've got the SFTP command as needed you then can call it from within SAS using Filename Pipe.

Shahrukhh_Khan
Fluorite | Level 6
Thanks Patrick for your reply.
JasonDiVirgilio
Quartz | Level 8

Refer to the link to SAS Documentation I included. Example 4 uses the DIR option to the filename statement when using SFTP. It gives you a directory listing as output which you can then parse to figure out what files you want to include.

 

Example 4: Reading Files from a Directory on the Remote Host

This example reads the files test.dat and test2.dat from a directory on the remote host.

 
filename infile sftp '/users/xxxx/' host="unixhost1" dir;
data _null_;
   infile infile(test.dat) truncover;
   input a $25.;
   infile infile(test2.dat) truncover;
   input b $25.;
run;
Shahrukhh_Khan
Fluorite | Level 6
Thanks Jason,

I will try DIR option in my code.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 6 replies
  • 4067 views
  • 3 likes
  • 3 in conversation