BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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


 

 

6 REPLIES 6
andreas_lds
Jade | Level 19

Do you want to extract the date from the filename or get the date shown in file explorer?

Ronein
Meteorite | Level 14

No,

I want to extract date from the date the file was created lastly

Ronein_0-1679905280245.png

 

LinusH
Tourmaline | Level 20

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:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.h...

 

Data never sleeps
andreas_lds
Jade | Level 19

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.

Tom
Super User Tom
Super User

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 .

----------------------------------------------------------------------------*/

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 766 views
  • 1 like
  • 5 in conversation