Desktop productivity for business analysts and programmers

SFTP with current date in filename

Reply
Occasional Contributor
Posts: 10

SFTP with current date in filename

[ Edited ]
data trial;
input filename $ number $;
datalines;
testtest 999
;
run; /*code 1*/ %ds2csv(data=trial, colhead=N, runmode=b, csvfile=D:\testing2\&date.file_trial1.csv); /*code 2*/ filename outfile1 sftp '/c:/dummy/&date.file_trial1.csv' USER="dummy_123" host="821.12.23.321" optionsx= "-i d:\dummy_key.ppk -pw testing000" DEBUG; PROC EXPORT Data = test trial= outfile1 DBMS=csv REPLACE;run; run;

 

 

 Hi all,

 

Would require help in this. 

 

my code works for code 1, which means the file saved in my d drive is 180704.file_trial1.csv

 

while the file saved for code 2 is &date.file_trial1.csv

 

Would kindly seek assistance on how to pass current date over to that file that requires to be sftp over.

 

Thank you.

 

Super User
Super User
Posts: 9,829

Re: SFTP with current date in filename

Posted in reply to brighterlight

You need to put double quotes around macro variables to get them to resolve:

filename outfile1 sftp "/c:/dummy/&date.file_trial1.csv" USER="dummy_123" host="821.12....

You could also simplfy by removing the &date macro variable and using a function:

filename outfile1 sftp "/c:/dummy/%sysfunc(date(),date9.)_file_trial1.csv" USER="dummy_123" host="821.12....

 However, I recommend not putting data in filenames, data should go in the data area as this makes further processing far simpler, and doesn't break version control systems and such like.  For instance, we refuse to accept dated, version number  or any such thing in files, they should all have the same name so the version control system can keep the history, and out users do not need to code for this.

Occasional Contributor
Posts: 10

Re: SFTP with current date in filename

Hi thanks for the reply. Unfortunately, I have tried it before as well, it doesn't work. 

 

 

Super User
Super User
Posts: 9,829

Re: SFTP with current date in filename

Posted in reply to brighterlight

"it doesn't work" - this does not tell us anything.

Occasional Contributor
Posts: 10

Re: SFTP with current date in filename

[ Edited ]

The file that was SFTP over was %sysfunc(date(),date9.)_file_trial1.csv

 

There wasn't any error so there's nothing much I can mention about it.

PROC Star
Posts: 398

Re: SFTP with current date in filename

Posted in reply to brighterlight

Hi!

I think it is easier to create the file name in a data step first. In that way you can check everything before defining the filename.

 

data createdFilename;
date = put(date(),date9.);
filename = cats(date,'_file_trial1.csv');
call symput('_fn',filename);
run;

%put &_fn;

filename outfile1 sftp "&_fn" USER="dummy_123" host="821.12.23.321" optionsx= "-i d:\dummy_key.ppk -pw testing000" DEBUG;
PROC EXPORT Data = test trial= outfile1 DBMS=csv REPLACE;run;
run;

//Fredrik

 

Occasional Contributor
Posts: 10

Re: SFTP with current date in filename

Hi Fredrik,

 

Thanks but this will not work either because a location is need, the statement which you have after sftp excludes the location and I need the file name as well. 

PROC Star
Posts: 398

Re: SFTP with current date in filename

Posted in reply to brighterlight

uhum, ok, but then you just add it to the _fn variable in the datastep or what?

The thing with the macro variable is that it can contain anything you need, passwords, paths, options and so on,...Smiley Happy

//Fredrik

Ask a Question
Discussion stats
  • 7 replies
  • 114 views
  • 0 likes
  • 3 in conversation