Hi all,
I have this logic to retrieve all file inside a folder, I want to add last modified or created date of the file inside.
Where can I add and what procedure to use? Thanks
/*FIND PATH PARENT*/
%let pathbase=G:\Shared drives\;
data filebase;
length fref $8 fname $200;
did = filename(fref,"&pathbase.");
did = dopen(fref);
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
did = dclose(did);
did = filename(fref);
keep fname i;
run;
Hi @febyinkasid,
You can use the MOPEN, FINFO and FCLOSE functions:
/*FIND PATH PARENT*/ %let pathbase=G:\Shared drives\; data filebase; length fref $8 fname $200; did = filename(fref,"&pathbase."); did = dopen(fref); do i = 1 to dnum(did); fname = dread(did,i); fid=mopen(did, fname); created=input(finfo(fid,'Create Time'),nldatm200.); lastmod=input(finfo(fid,'Last Modified'),nldatm200.); rc=fclose(fid); output; end; did = dclose(did); did = filename(fref); format created lastmod e8601dt.; keep fname i created lastmod; run;
Hi, Thank You...
I cant retrieve the date, though there is no error in log
It worked with a local directory on my Windows workstation. What does the PUT statement write to the log if you add it like in the modified code below?
data filebase; length fref $8 fname created lastmod $200; did = filename(fref,"&pathbase."); did = dopen(fref); do i = 1 to dnum(did); fname = dread(did,i); fid=mopen(did, fname); put fid=; created=finfo(fid,'Create Time'); lastmod=finfo(fid,'Last Modified'); rc=fclose(fid); output; end; did = dclose(did); did = filename(fref); keep fname i created lastmod; run;
I've also simplified the assignment statements for the two new variables by using their default (character!) format. Note the deletion of the FORMAT statement.
Oooh it workss! I think I wrote a path that consists of folder thats why.
Thank You so much
Use this macro: https://github.com/sasutils/macros/blob/master/dirtree.sas
Of just read the macro to see how it is finding the date for each file. Basically you have to open each file so that you can use the FINFO() function.
Note that FINFO() wants the NAME of the option passed to it, but the name it wants depends on the language settings of your session, so use the FOPTNAME() function to find the right name to use. Also the string returned depends on the language setting, so use the right informat to convert to a value datetime value.
lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);
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.
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.