Overview
There is a nifty little utility that has been around forevertm on *nix systems which interprets the "Magic" number of a file and displays what that particular file is used for - the aptly named file utility. This article will show you how to modify the default magic number configuration so that the file utility will identify all SAS file types as well as display the version and platform that they were created on.
The file Utility
Here is an example use of the file utility - to check if a "*.txt" file is really just ASCII Text:
[sas@linuxserver ~]$ file worklist.txt worklist.txt: ASCII text
The utility works by using rules found inside a magic file, which on RedHat usually lives at /usr/share/file/magic
The default magic file should already contain some simple checks to identify the following SAS file types:
- Data File
- Catalog
- Data File Index
- Data View
Here is the default output when running the file command against some SAS 9.1 files:
[sas@linuxserver sasuser.v91]$ file * classpgm.sas7bpgm: SAS 7+ class.sas7bdat: SAS 7+ data file classv.sas7bvew: SAS 7+ data view prdmddb.sas7bmdb: SAS 7+ profile.sas7bcat: SAS 7+ catalog regstry.sas7bitm: SAS 7+
And here is the output from running file against some SAS 9.3 files:
[sas@linuxserver sasuser.v93]$ file * classpgm.sas7bpgm: SAS 7+ class.sas7bdat: SAS 7+ data file classv.sas7bvew: SAS 7+ data view prdmddb.sas7bmdb: SAS 7+ profile.sas7bcat: SAS 7+ catalog regstry.sas7bitm: SAS 7+
While the output is somewhat useful, SAS files also contain information on what version of SAS created them as well as what Platform. The default configuration also doesn't know about file types other than Datasets, Indexes, Views and Catalogs.
Updating the magic
Giving the default magic number file some tweaks, we can get output like this:
[sas@linuxserver sasuser.v91]$ file * classpgm.sas7bpgm: SAS StoredProgram 9.0101M3Linux x86_64 Linux class.sas7bdat: SAS Dataset 9.0101M3Linux x86_64 Linux classv.sas7bvew: SAS View 9.0101M3Linux x86_64 Linux prdmddb.sas7bmdb: SAS MDDB 9.0101M3Linux x86_64 Linux profile.sas7bcat: SAS Catalog 9.0101M3Linux x86_64 Linux regstry.sas7bitm: SAS ItemStore 9.0101M3Linux x86_64 Linux
..and this...
[sas@linuxserver sasuser.v93]$ file * classpgm.sas7bpgm: SAS StoredProgram 9.0301M2Linux x86_64 class.sas7bdat: SAS Dataset 9.0301M2Linux x86_64 classv.sas7bvew: SAS View 9.0301M2Linux x86_64 prdmddb.sas7bmdb: SAS MDDB 9.0301M2Linux x86_64 profile.sas7bcat: SAS Catalog 9.0301M2Linux x86_64 regstry.sas7bitm: SAS ItemStore 9.0301M2Linux x86_64
..and even this (identifying Windows SAS files on Linux)...
[sas@linuxserver win.sasuser.v93]$ file * classpgm.sas7bpgm: SAS StoredProgram 9.0301M2NET_SRV NET_SRV class.sas7bdat: SAS Dataset 9.0301M2NET_SRV NET_SRV classv.sas7bvew: SAS View 9.0301M2NET_SRV NET_SRV prdmddb.sas7bmdb: SAS MDDB 9.0301M2NET_SRV NET_SRV profile.sas7bcat: SAS Catalog 9.0301M2NET_SRV NET_SRV regstry.sas7bitm: SAS ItemStore 9.0301M2NET_SRV NET_SRV
It is now possible to check a SAS file at the operating system level before attempting to use it to determine if there will be any version conflicts, etc.
For example, using the output of the file command against a View file (i.e. .sas7bvew file) you can determine programmatically whether opening that view is a good idea, avoiding messages such as:
WARNING: File SASUSER.CLASSV.VIEW was created for a different operating system.
ERROR: The view SASUSER.CLASSV was created on an incompatible host and cannot execute on this host.
Here are the tweaked settings for the magic number file:
# SAS magic data for file(1) command. 0x54 string SAS SAS >0x9C string DATA Dataset >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string CATALOG Catalog >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string INDEX Index >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string VIEW View >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string ITEMSTOR ItemStore >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string MDDB MDDB >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string UTILITY Utility >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string PROGRAM StoredProgram >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string ACCESS AccessDescriptor >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string AUDIT Audit >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string FDB ConsolidationDB >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string SASODS ODS >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string DMDB DataMiningDB >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string PUTILITY PermanentUtility >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s >0x9C string BACKUP Backup >>0xD8 string x %s >>>0x110 string x %s >>0xE0 string x %s >>>0x118 string x %s
The above configuration is also in the attached .magic file.
Please refer to the file and magic man pages for information on how to incorporate these updated magic file settings into your *nix system.
Comments
0 comments
Article is closed for comments.