SAS Last Date Modified

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

SAS Last Date Modified

[ Edited ]

Hi, I am trying to get the last date modified for an EXCEL sheet, however the returned value is blank not sure why. I am running the following bit of code on SAS 9.4.

 

 


%let specname = XXX99999 Mapping v0.1;

%let rc = %sysfunc(filename(onefile, %str(.\Docs\&specname..xls))));
%let fid = %sysfunc(fopen(&onefile.));
%let modifydt = %sysfunc(finfo(&fid, Last Modified));
%let fidc = %sysfunc(fclose(&fid.));
%let rc = %sysfunc(filename(onefile));

The log then shows this,

 

SYMBOLGEN: Macro variable MODIFYDT resolves to

   

Any ideas why this may happen?


Accepted Solutions
Solution
‎08-01-2016 04:25 AM
Esteemed Advisor
Posts: 6,646

Re: SAS Last Date Modified

I find it MUCH more convenient to avoid the %sysfunc and %str hailstorm by using a data _null_ step:

(This is UNIX, of course)

data _null_;
rc = filename("onefile","$HOME/test.txt");
fid = fopen("onefile");
modifydt = finfo(fid,"Last Modified");
call symput('modifydt',modifydt);
run;

%put &modifydt.;

The correct parameter for the finfo function is "Last Modified", as per FINFO Function: Windows

Result here:

16         data _null_;
17         rc = filename("onefile","$HOME/test.txt");
18         fid = fopen("onefile");
19         modifydt = finfo(fid,"Last Modified");
20         call symput('modifydt',modifydt);
21         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

22         
23         %put &modifydt.;
Tue Jun 28 08:53:29 2016
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Grand Advisor
Posts: 17,316

Re: SAS Last Date Modified

Contributor
Posts: 39

Re: SAS Last Date Modified

Sorry I have updated this, I left this in by mistake, when I use Last my result is still null Smiley Frustrated

Solution
‎08-01-2016 04:25 AM
Esteemed Advisor
Posts: 6,646

Re: SAS Last Date Modified

I find it MUCH more convenient to avoid the %sysfunc and %str hailstorm by using a data _null_ step:

(This is UNIX, of course)

data _null_;
rc = filename("onefile","$HOME/test.txt");
fid = fopen("onefile");
modifydt = finfo(fid,"Last Modified");
call symput('modifydt',modifydt);
run;

%put &modifydt.;

The correct parameter for the finfo function is "Last Modified", as per FINFO Function: Windows

Result here:

16         data _null_;
17         rc = filename("onefile","$HOME/test.txt");
18         fid = fopen("onefile");
19         modifydt = finfo(fid,"Last Modified");
20         call symput('modifydt',modifydt);
21         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

22         
23         %put &modifydt.;
Tue Jun 28 08:53:29 2016
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 39

Re: SAS Last Date Modified

This worked, I added a bit of code to change the format though

 

modifydt = finfo(fid,"Last Modified");
lastmodified = input((trim(scan(modifydt, 1, " ") || substrn(scan(modifydt, 2, " "), 1, 3) || scan(modifydt, 3, " ")) || ":" || scan(modifydt, 4, " ")), datetime20.);

Contributor
Posts: 39

Re: SAS Last Date Modified

Hi, quick question how do I close the file? I tired 

 

fid = fclose ("onefile");

 

But it doesnt work

Esteemed Advisor
Posts: 6,646

Re: SAS Last Date Modified

To close the file and reset the file reference, do

rc = fclose(fid);
rc = filename("onefile");
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Grand Advisor
Posts: 9,571

Re: SAS Last Date Modified

Or Dictionary table .




filename xx '/folders/myfolders/xx.rtf';
proc sql;
select * 
 from dictionary.EXTFILES
  where fileref='XX';
quit;




Grand Advisor
Posts: 9,571

Re: SAS Last Date Modified

Or querying Dictionary table .

filename xx '/folders/myfolders/xx.rtf';
proc sql;
select * 
 from dictionary.EXTFILES
  where fileref='XX';
quit;




☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 568 views
  • 4 likes
  • 4 in conversation