All,
trying to get list of files and modified date in a dataset . list of files is working but not modified date.
filename myDir "/work" ;
data test (keep=filename modified);
did=dopen("myDir") ;
filecount=dnum(did) ;
do i=1 to filecount ;
fid = fopen('myDir');
filename=dread(did,i) ;
modified=finfo(fid,"Last Modified");
put filename= ;
output ;
fid=fclose(fid);
end ;
rc=dclose(did) ;
run ;
Make your code well-behaving by cleaning up all references it creates:
data test (keep=fname modified);
length fref $8;
if filename(fref,"/work") = 0
then do;
did = dopen(fref);
if did ne 0
then do;
dnum = dnum(did);
do i = 1 to dnum;
fname = dread(did, i);
fid = mopen(did, fname);
if fid ne 0
then do;
modified = finfo(fid,'Last Modified');
output;
fid = dclose(fid);
end;
end;
did = dclose(did);
end;
rc = filename(fref);
end;
run;
as otherwise it will have "memory leaks" by accruing file references and file handles.
please try dictionary.tables as below from libname , you will see column memname with list and modate with modified date
libname adam '~path of datasets';
proc sql;
create table want as select * from dictionary.tables where libname='ADAM' ;
quit;
Alternatively via data step
data want;
set sashelp.vtable;
where libname='ADAM' ;
keep modate memname;
run;
please try this code as well
data test (keep=filename modified);
length fref $8;
rc=filename(fref,"/work");
if rc = 0 then do;
did = dopen(fref);
rc = filename(fref);
end;
dnum = dnum(did);
do i = 1 to dnum;
filename = dread(did, i);/* If this entry is a file, then output. */
fid = mopen(did, filename);
modified=finfo(fid,'Last Modified');
if fid > 0 then output;
end;
rc = dclose(did);
run;
Make your code well-behaving by cleaning up all references it creates:
data test (keep=fname modified);
length fref $8;
if filename(fref,"/work") = 0
then do;
did = dopen(fref);
if did ne 0
then do;
dnum = dnum(did);
do i = 1 to dnum;
fname = dread(did, i);
fid = mopen(did, fname);
if fid ne 0
then do;
modified = finfo(fid,'Last Modified');
output;
fid = dclose(fid);
end;
end;
did = dclose(did);
end;
rc = filename(fref);
end;
run;
as otherwise it will have "memory leaks" by accruing file references and file handles.
Actually, I do not think "cleaning up" is strictly necessary in a data step. It seems that SAS takes case of cleaning up when the data step ends. For instance:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 filename x "%sysfunc(pathname(WORK))";
74
75 data _null_;
76 did=dopen('x');
77 put _ALL_;
78 run;
did=1 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
79
80 data _null_;
81 did=dopen('x');
82 put _ALL_;
83 run;
did=1 _ERROR_=0 _N_=1
So what we see is that the directory handle number (DID=1) get reused in the second step, because it becomes deallocated as the data step ends.
In macros, om the other hand, and probably also in SAS/SCL programming, cleanup is not automatic, and is good practice.
Yes, but ...
On UNIX systems it is standard to set the number of available file handles for a user to something like 2000 per default, and that can quickly be used in a step that works through a "industrially populated" directory. Or once one starts to work with code that reads multiple directories in one step.
Yes, of course! You can hit the ceiling in a single datastep if you do not close the handles. Thanks!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.