Good morning.
I wanted to ask a general question about output file last modified date. I don't have example code so I was looking for a hint or just a general direction to search to see if it's possible for SAS to set the output file last modified date to a different defined date? For instance, if I have an ODS EXCEL or PROC EXPORT process at 9:30 AM on May 5, that will become the output file last modified date. Can I force that last modified date to be a different date and time? Is there such a feature in SAS?
Thanks for any direction someone could point me.
You could wrap the powershell portion into a function using Proc FCMP and compile the function to somewhere it's available to users.
Below some PoC that works in my environment. Needs option XCMD.
proc fcmp outlib=work.funcs.trial;
function change_file_mod_dt(path_file $);
cmd='powershell -command "(Get-Item ''C:\test\test.txt'').LastWriteTime=(''12 December 2016 14:00:00'')"';
rc=system(cmd);
return(rc);
endsub;
options cmplib=work.funcs;
data _null_;
rc=change_file_mod_dt('C:\test\test.txt');
put rc=;
run;
In Windows, Powershell can change the last modified date. So you need to use SAS to issue a Powershell command
(Thanks @ChrisHemedinger eleven years ago)
My fault, I should have given more information, sorry.
I'm trying to stay away from Power Shell in that there are times "recoders/code fixers" are not all that experienced. I'd like to stay away from methods that would allow a novice the ability to "discover" ways to user such powerful commands. It's also important that the method be as simple as possible so those same novice users can adjust it if anything breaks in the future. I was so hoping there was just a simple way to reset one of the file properties on file generation.
Forgetting SAS, if you had to do this outside of SAS, as far as I know there are two methods: manually, and via Powershell. Are you aware of any other method of changing this date?
I am not. The reason I need it changed is we are importing the file to Power BI and the import process requires a two digit modified time. If the file runs prior to 10 AM the time digits are only one digit.
I guess I might have to figure out a different way to accomplish this.
You could wrap the powershell portion into a function using Proc FCMP and compile the function to somewhere it's available to users.
Below some PoC that works in my environment. Needs option XCMD.
proc fcmp outlib=work.funcs.trial;
function change_file_mod_dt(path_file $);
cmd='powershell -command "(Get-Item ''C:\test\test.txt'').LastWriteTime=(''12 December 2016 14:00:00'')"';
rc=system(cmd);
return(rc);
endsub;
options cmplib=work.funcs;
data _null_;
rc=change_file_mod_dt('C:\test\test.txt');
put rc=;
run;
Doesn't Windows provide a simple command like the UNIX touch?
@Kurt_Bremser wrote:
Doesn't Windows provide a simple command like the UNIX touch?
I just Googled how to change the modification date in Windows using Powershell and nothing as simple as touch came up.
@Jeff_DOC wrote:
I am not. The reason I need it changed is we are importing the file to Power BI and the import process requires a two digit modified time. If the file runs prior to 10 AM the time digits are only one digit.
I guess I might have to figure out a different way to accomplish this.
I think perhaps you have a different problem here. Whether the time is before 10AM should make NO difference at all. I think perhaps you are trying to use a sledge hammer to swat a fly.
In SAS if you want to print a time value with leading zeros on the hour use the TOD format instead of the TIME format.
376 data _null_; 377 do time='08:00't,'10:00't; 378 put time comma7. +1 time tod8. +1 time time8.; 379 end; 380 run; 28,800 08:00:00 8:00:00 36,000 10:00:00 10:00:00
I'm guessing you want the last modified date to match the timestamp of the data source? I understand the ask, but I don't think there is a SAS function for it. FINFO can get this info for you, but that just calls into the standard OS functions for retrieving file info. @PaigeMiller is correct: you need special tools to touch the file and reset the date.
Other ways to call external code include PROC FCMP (supports Python in SAS 9.4 Maint 6 and 7), PROC GROOVY, PROC LUA. But not sure if any of those would open the door for you. (And in SAS Viya, we have PROC PYTHON.)
Thank you very much to everyone who took the time to reply. The solution appears to be more complicated than I anticipated. I think they are all great solutions but unfortunately I can only mark one as a solution.
Again, thank you all.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: