Getting the FINFO from Your Files
The FINFO function can be used to gain a number of file attributes from the Windows file system. A total of six attributes named ‘info items’ can be identified through the use of the FINFO function and are formatted as below.
|Info Item||Description||Example Output|
|Create Time||The time that the file was created||21 October 2015 09:24:07 o'clock|
|Last Modified||The last time the file was modified||21 October 2015 09:24:07 o'clock|
|Filename||File name including file extension||Class Names.csv|
|File size (bytes)||The size of the file in bytes||25145|
The Record Format as below:
V = Variable, each record ends in a newline character.
F = Fixed, each record has the same length.
N = Binary, the file has no record boundaries.
P = Print, the SAS System write carriage-control characters.
D = Default Format (same as variable)
|LRECL||The Logical Report Length - the length of the input buffer created during DATA step processing.||32767|
In order to access the info items for a single file, the FOPEN function must be used to return a file identifier for the file and allow the file to be opened for input. Once the file is opened the FINFO functions can be used to access the info items required. Finally, it is important to close the file using the SYSRC=FCLOSE function. This closes the file and outputs a system return code of 0 for a file that has been successfully closed or not 0 for a file that was unsuccessful.
The data for the Class Names file can be seen in the table below:
Sometimes it can be useful to gain the FINFO from a number of files in a directory. There are in total ten files stored within this location.
Three extra functions are available to make it possible to read in the FINFO from a directory of files. These functions are the DOPEN, DNUM and DREAD functions. When utilised effectively, they can be used to create a loop of all of the files within the directory in order to read the FINFO for each of the files. The DOPEN function similarly to the FOPEN function returns a directory identifier and allows the directory to be opened for input. The DNUM function can be used to count the number of files within the opened location which can be used within a do loop to loop through all of the files in the location. DREAD can then be utilised to read each file within this directory making each file accessible for the FOPEN and FINFO functions.
At the end of the process a DCLOSE function is available to close the directory after processing. The final data set contains all of the ten files stored within the location with the last modified date and file size in bytes for each file.
Click here for access to more SAS help via Amadeus' complete collection of SAS Programming tips.