BookmarkSubscribeRSS Feed
NiravC
Obsidian | Level 7

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

5 REPLIES 5
FredrikE
Rhodochrosite | Level 12

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;

NiravC
Obsidian | Level 7
hii Fredrike,

Is this file move code?
I didn't get it anything this code.
can you explain it out?
Kurt_Bremser
Super User

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.

NiravC
Obsidian | Level 7

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

Kurt_Bremser
Super User

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1342 views
  • 0 likes
  • 3 in conversation