07-04-2018 04:23 AM - edited 07-04-2018 04:24 AM
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="822.214.171.1241" optionsx= "-i d:\dummy_key.ppk -pw testing000" DEBUG; PROC EXPORT Data = test trial= outfile1 DBMS=csv REPLACE;run; run;
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.
07-04-2018 04:44 AM
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.
07-04-2018 09:33 PM - edited 07-04-2018 09:47 PM
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.
07-05-2018 03:40 AM
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="8126.96.36.1991" optionsx= "-i d:\dummy_key.ppk -pw testing000" DEBUG; PROC EXPORT Data = test trial= outfile1 DBMS=csv REPLACE;run; run;
07-05-2018 04:56 AM
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.
07-05-2018 07:12 AM
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,...