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

I recently came across your solution post about how to get the list of the files in a folder using the SAS functions.  Extension to that request, I would like to get the last modified or created dates of those files as variable in my dataset. Is  there any SAS function that will helps us to get it? I am sorry if this question already answered ( unfortunately I could not find it). Here is the old post and solution link (thanks to @Kurt_Bremser ).

Old post link:https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/td-p/674065 

 

data filenames;
length fref $8 fname $200;
did = filename(fref,'&path');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  output;
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

For every file found, define a FILENAME like for the directory (use a different fref variable). Use FOPEN to open the file, then you can use the FOPTNUM, FOPTNAME and FINFO functions to get the file metadata. Read the relevant documentations for this.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

For every file found, define a FILENAME like for the directory (use a different fref variable). Use FOPEN to open the file, then you can use the FOPTNUM, FOPTNAME and FINFO functions to get the file metadata. Read the relevant documentations for this.

Ksharp
Super User

Or try dictionary table.

 

filename x1 'c:\temp\class.txt';
filename x2 'c:\temp\subtitle.txt';

proc sql;
select * from dictionary.EXTFILES
where Fileref in ('X1' 'X2');
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1129 views
  • 2 likes
  • 4 in conversation