Hi All,
I want to move external(xlsx) file one location to another location with suffix Datetime.
My file name is Myexcel.xlsx
I use this code:
%let tdate=%sysfunc(datetime(),datetime.);
x %unquote(%str(%')move "D:\PM\Myexcel.xlsx" "D:\Myexcel&tdate..xlsx"%str(%'));
But this code is not work. When I remove macro refrence then code is work.But I want when I am moving this file then name should be "Myexcel02Jul2019 02:32 PM.xlsx"
How to move file with suffix datetime ?Can you explain it?
Thanks in advance,
Nirav
Hi!
Can you try something like this instead, to see if it works?
//Fredrik
%let tdate=%sysfunc(datetime(),datetime.);
%let cmd = cp sasv9_usermods.cfg sasv9_usermods&tdate..cfg;
filename test pipe "&cmd";
data test;
length result $200;
infile test truncover delimiter='|';
input result ;
run;
Run your move code with filename pipe:
%let tdate=%sysfunc(datetime(),e8601dt19.);
filename oscmd pipe "move 'D:\PM\Myexcel.xlsx' 'D:\Myexcel&tdate..xlsx' 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
and look at the log, If puzzled, post the log here, using the {i} button.
Since the single quotes are masked by the outer double quotes, the macro variable will be resolved.
And I used a ISO format for the timestamp, which makes much more sense than the standard SAS datetime format.
Hi KurtBremser,
Here is the log: 26 %let tdate=%sysfunc(datetime(),e8601dt19.); 27 28 filename oscmd pipe "move 'D:\SAS_DATA_IMPORT\66-0217\PM\IPR_A.xlsx' 'D:\IPR_A&tdate..xlsx' 2>&1"; 29 30 data _null_; 31 infile oscmd; 32 input; 33 put _infile_; 34 run; NOTE: The infile OSCMD is: Unnamed Pipe Access Device, PROCESS=move 'D:\SAS_DATA_IMPORT\66-0217\PM\IPR_A.xlsx' 'D:\IPR_A2019-07-03T09:21:29.xlsx' 2>&1, RECFM=V,LRECL=32767 The filename, directory name, or volume label syntax is incorrect. NOTE: 1 record was read from the infile OSCMD. The minimum record length was 66. The maximum record length was 66. NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.01 seconds
I used this code but file is not moving.Can you explain to me what should I do next?
Nirav
Windows obviously does not like colons in filenames (just tested that), so you should use the b8601dt15. format for creating the timestamp (no hyphens, no colons).
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.