BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jeff_DOC
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

 

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

In Windows, Powershell can change the last modified date. So you need to use SAS to issue a Powershell command

 

https://blogs.sas.com/content/sasdummy/2011/09/15/calling-windows-powershell-from-sas-a-simple-examp...

 

(Thanks @ChrisHemedinger eleven years ago)

--
Paige Miller
Jeff_DOC
Pyrite | Level 9

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. 

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
Jeff_DOC
Pyrite | Level 9

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.

Patrick
Opal | Level 21

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;

 

Patrick
Opal | Level 21

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

Tom
Super User Tom
Super User

@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
ChrisHemedinger
Community Manager

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

SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
Jeff_DOC
Pyrite | Level 9

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

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
  • 10 replies
  • 1727 views
  • 3 likes
  • 6 in conversation