SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
craig159753
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

8 REPLIES 8
craig159753
Quartz | Level 8

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

Kurt_Bremser
Super User

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
craig159753
Quartz | Level 8

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

craig159753
Quartz | Level 8

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

 

fid = fclose ("onefile");

 

But it doesnt work

Ksharp
Super User
Or Dictionary table .




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




Ksharp
Super User
Or querying Dictionary table .

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




sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 8 replies
  • 8371 views
  • 4 likes
  • 4 in conversation