BookmarkSubscribeRSS Feed
hotprawnstar
Calcite | Level 5

Hi There,

 

I'm trying to read a CSV file from a SFTP folder. The customers have instructed that the filename would vary day to day due to a datetime stamp in the file name. However the file that needs to be imported into SAS will be the only file sitting in the SFTP folder everyday.

 

Is there a way to get SAS to import the only file that is sitting in this SFTP folder instead of having to specify the filename explicitly? I'm on version 7.1 btw.

 

Thanks!

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Personally, if I was paying them to send me data I would be telling them how to provide the data.  Hence my import agreement would define structure, content, and delivery details which they would then sign and abide by.  As part of the delivery details I would instruct them to name the file the same each time, without filename modifications, so you wouldn't need to worry about that (and your version control system would be able to handle this text file). 

Kurt_Bremser
Super User

I don't think it's possible to use the SAS directory functions over SFTP.

So I'd use an external SFTP utility to extract all files found to a local directory (clean it out first!), and then use the SAS directory functions to retrieve the filename.

Damo
SAS Employee

Hi,

 

Did you try to use the LS option coming with the SFTP method of FILENAME?

From the SAS® 9.4 Statements: Reference, Fifth Edition and its FILENAME Statement, SFTP Access Method chapter, we have:

LS.JPG

 

Other options such as LSFILE, etc. might help you too.

 

 

From that same page, you'll also have access to Exemple 4: Reading Files from a Directory on the Remote Host.

This can be done after you retrieved the file name:

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;

 

Hope that helps.

(Sorry I can't test, i don't have a SFTP available).

 

Cheers,
Damo

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
  • 3 replies
  • 769 views
  • 0 likes
  • 4 in conversation