BookmarkSubscribeRSS Feed
PerBundgaard
Obsidian | Level 7

Hi, I'd appreciate your input

My program takes an Excel file with control values as input.

I want to make sure the Excel file gets a new modified date when my program executes.

A SAS consultant suggested this approach:
x "cd ""&Indir.""";
filename copy pipe "copy /b ""&Infile."" +,,";
data _NULL_;
infile copy;
input;
put _INFILE_;
run;
filename copy clear; 

But I get the error message:

"

The system cannot find the file specified.
Stderr output:
'...Input directory...'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.

"

 

Can this approach be made to work or do you have an alternative solution
 Thanks

15 REPLIES 15
Tom
Super User Tom
Super User

You want to change the date on the input file?  But you don't want to actually generate a new file?

What operating system is your SAS session running under?  Does it support the touch command?

%let original_file=\\some_server\some_share\some_directory\some_file.xlsx;
data _null_;
  infile "touch &original_file" pipe ;
  input;
  put _infile_;
run;
PerBundgaard
Obsidian | Level 7
Yes, just right
I want to 'touch' file just enough for it to get a new modified date
I'm in a windows setting, not sure touch command is for windows, but I'll try it out
Thanks and best
LeonidBatkhan
Lapis Lazuli | Level 10

Hi PerBundgaardLarsen,

You can "touch" your file using the following 2 commands:

x "cd ""&indir""";
x "copy /b ""&infile""+";

Hope this helps.

PerBundgaard
Obsidian | Level 7
Hmm, I afraid not, but thanks
Tom
Super User Tom
Super User

@LeonidBatkhan wrote:

Hi PerBundgaardLarsen,

You can "touch" your file using the following 2 commands:

x "cd ""&indir""";
x "copy /b ""&infile""+";

Hope this helps.


You seemed to have missed the original question as that is the code they started with.  The problem with that code is the CD command because the shell does not let you CD to a UNC path, only something with a drive letter assigned. Fortunately the CD command is not needed.  Note if you use a data step to run the commands instead of the X command then you can capture the messages the operating system returns.

data _null_;
  infile "copy /b ""&indir\&infile""+" pipe;
  input;
  put _infile_;
run;

 

PerBundgaard
Obsidian | Level 7

I really appreciate the suggestions, but doesn't seem to be possible to "touch" an external file due to UNC or what am I missing ? Thanks


NOTE: The infile "copy /b
""\\UNC-path\Input.xlsx"
"+" is:
Unnamed Pipe Access Device,

PROCESS=copy /b
"\\UNC-pathInput.xlsx"+
,
RECFM=V,LRECL=32767

0 file(s) copied.
Stderr output:
'\\UNC-path'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Access is denied.
NOTE: 1 record was read from the infile "copy /b
""\\UNC-path\Input\Input.xlsx"
"+".
The minimum record length was 25.
The maximum record length was 25.
NOTE: DATA statement used (Total process time):
real time 0.41 seconds
cpu time 0.06 seconds

Tom
Super User Tom
Super User

Your earlier CD command has still messed up the default path.

Try starting a new session and make sure not to run the CD commands.

 

PS Remember to use the Insert Code button in the editor to get a pop-up for pasting your text so the forum doesn't try to format it.

PerBundgaard
Obsidian | Level 7

Thanks for your advice on starting a new SAS session and for inserting code using the pop-up

I've actually started a new SAS session with every attempt and this time restarted the PC

I'm afraid I still have no luck, please refer inserted log. The difference seems to be that the cmd now starts in \\UNC-path2 where the program resides

Please advice and best

 

data _null_;
    infile "copy /b ""&indir\&infile""+" pipe;
    input;
    put _infile_;
run;

NOTE: The infile "copy /b
      ""\\UNC-path1\Input.xlsx"
      "+" is:
      Unnamed Pipe Access Device,

      PROCESS=copy /b
      "\\UNC-path1\Input.xlsx"+
      ,
      RECFM=V,LRECL=32767

        0 file(s) copied.
Stderr output:
'\\UNC-path2'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Access is denied.
NOTE: 1 record was read from the infile "copy /b
      ""\\UNC-path1\Input.xlsx"
      "+".
      The minimum record length was 25.
      The maximum record length was 25.
NOTE: DATA statement used (Total process time):
      real time           0.51 seconds
      cpu time            0.06 seconds
Tom
Super User Tom
Super User

That is interesting.

Here is a method to find your current working directory without using PIPE.

data _null_;
  length fileref $8 directory $256 ;
  rc=filename(fileref,'.');
 directory=pathname(fileref);
  rc=filename(fileref);
  put directory=;
run;

Also check what operating system your SAS session is running on and even what machine.

%put &=SYSHOSTINFOLONG;
%put &=SYSHOSTNAME;

Try changing the current directory to someplace that does have a drive letter.  For example you might assume that the drive C: exists and use that.

You might be able to include it in the same command during the pipe:

infile "cd c:\ ; copy /b ""&indir\&infile""+" pipe;

But you might also need to run it separately.

x 'cd c:\';
LeonidBatkhan
Lapis Lazuli | Level 10

Hi PerBundgaardLarsen,

The bigger question to ask is why do you want to change a file's "modified date" when you do not modify the file, but only read it? I suspect you are solving the wrong problem...

Tom
Super User Tom
Super User

More likely an XY problem than a refrigerator problem.

PerBundgaard
Obsidian | Level 7

Thank you both Tom and Leonid

I loved the articles about the ice machine and the x vs y spending time on (wrong) problem solving :).

In this family we ended up recycling the ice machine due to the cord problem but more over since it was never really any good and consequently just sat there on the shelf. As for the x and y problem you're quite right too. This is just one of those times where you go down a hole thinking some smart guy must know a smart, slick solution to what you think is a problem without filling in on the whole story.

The utility program we want must take an Excel file in an UNC path as input for what files to delete in some specified folders and characterized by their last modified date and file extension. The control file resides in the same UNC path and we don't want the control file to qualify for deletion. One obvious solution would be to import and export the control file, which would give it new last modified date. but I read about the Linux/UNIX 'touch' approach and thought there might be a similar or workaround solution in a windows environment.

Thank you for your patience

LeonidBatkhan
Lapis Lazuli | Level 10
Then maybe move your control file to another folder and do not take into account "last modified date" for file deletion. Or create TODO_DONE list (data set) where you keep inventory of your files (FILENAME column) and STATUS column ("TODO" or "DONE" values) and/or DATE_DELETED column (. if to be deleted, and some real date when it was done). Just solve the problem instead of creating one.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 15 replies
  • 2533 views
  • 3 likes
  • 3 in conversation