BookmarkSubscribeRSS Feed
brighterlight
Fluorite | Level 6
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.

 

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

brighterlight
Fluorite | Level 6

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

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

brighterlight
Fluorite | Level 6

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.

FredrikE
Rhodochrosite | Level 12

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

 

brighterlight
Fluorite | Level 6

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. 

FredrikE
Rhodochrosite | Level 12

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,...:)

//Fredrik

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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