Hello
In specific path there are located many files with similar name.
The only difference between the file names is the date on the file name.
Let's say that there is a list of file name that I want to check when the file was created and put the information in a data set.
What is the way to do it please?
Let's say that I want to check it for the following files:
"/usr/local/SAS//score/daily_files/9.1.3.Loans.20230224"
"/usr/local/SAS//score/daily_files/9.1.3.daily.20230225"
"/usr/local/SAS//score/daily_files/9.1.3.daily.20230226"
The wanted data set will have 2 columns:
File_name
File_Date_Created
Do you want to extract the date from the filename or get the date shown in file explorer?
No,
I want to extract date from the date the file was created lastly
Of course there are OS command to explore this information.
If you want to do it from within SAS, take a look at FINFO and related functions:
This has been asked many times before, the search function will reveal code that will, most likely, just need some tweaks to work in your environment.
You just need to ask the operating system. If you have XCMD option turned on you can use a simple PIPE to read in the output of the operating system command.
If not then use the DOPEN(), DREAD(), and FINFO() functions.
Here is a %DIRTREE() macro that should make it trivial:
https://github.com/sasutils/macros/blob/master/dirtree.sas
Head of macro:
%macro dirtree
/*---------------------------------------------------------------------------
Build dataset of files in directory tree(s)
----------------------------------------------------------------------------*/
(directory /* Pipe delimited directory list (default=.) */
,out=dirtree /* Output dataset name */
,maxdepth=120 /* Maximum tree depth */
);
/*---------------------------------------------------------------------------
Use SAS functions to gather list of files and directories
directory - Pipe delimited list of top level directories
out - Dataset to create
maxdepth - Maximum depth of subdirectories to query
Output dataset structure
--NAME-- Len Format Description
FILENAME $256 Name of file in directory
TYPE $1 File or Directory? (F/D)
SIZE 8 COMMA20. Filesize in bytes
DATE 4 YYMMDD10. Date file last modified
TIME 4 TOD8. Time of day file last modified
DEPTH 3 Tree depth
PATH $256 Directory name
Size is not available for the directories.
LASTMOD timestamp is only available on Unix for directories.
Will not scan the subtree of a directory with a path that is
longer then 256 bytes. For such nodes TYPE will be set to L .
----------------------------------------------------------------------------*/
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.