SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 24818: Programmatically Determine Which Disk Drives are Available for Your Windows Server or Workstation

DetailsCodeAboutRate It
This SAS program quickly allows SAS Windows users to determine, programmatically, all of the Disk drives that are available to their server or workstation. (Even though "MVS" is my middle name, I currently do 95% of my SAS programming in either the UNIX or the Windows environments.)

This program, and the concept that it illustrates, will be helpful to SAS programmers in a number of ways:

  • SAS programmers can programmatically search for a particular Disk drive, and from there a particular directory first, before putting it in a LIBNAME or FILENAME statement.
  • SAS programmers can create a SAS "data base" of the following information, to characterize changes over time:
    • The individual directories allocated on a specific Disk drive or Disk drives.
    • The date on which directories or files on a specific Disk drive were last updated.
    • The sizes of files on a specific Disk drive.
    • The types of files stored on a particular Disk drive or in a directory — .bat, .txt, .sas, .sas7bdat, etc.
    • The number of directories and the number of files allocated to the root of a particular Disk drive.
  • SAS programmers can programmatically determine if a particular disk/directory/file is present. If not, they can issue an alert, error message or e-mail.
  • SAS programmers can execute this program via SAS/CONNECT to map out the directories of remote Windows servers.
  • Consultants (such as myself) can run it to get a quick look at the environment on the PC they will be working on. The output is saved in a file that they can refer to later, off-site.
I was inspired to write this program the day that I received my new copy of SAS Companion for the Microsoft Windows Environment, Version 8. On page 375, I came across the DRIVEMAP option of the FILENAME statement and was immediately intrigued. As I said, I think others will find the following program helpful!

*****************************************************************;
* SAS Options.                                                  *;
*****************************************************************;
options noxwait xmin xsync;


*****************************************************************;
* Set Drives to skip over. The default is the mountable drives  *;
* A: - diskette and D: - CD ROM. Make changes if you have these *;
* devices mounted or have alternate drives mapped for mountable *;
* devices. This program will hang if you attempt to map a       *;
* mountable drive that does not have media mounted in it.       *;
*****************************************************************;
%LET SKIPDEVS = 'A:' 'D:';


*****************************************************************;
* Set the output file that will contain the concatenated output *;
* of the DOS "DIR" command executed for each Drive. Change this *;
* value if you need an alternative.                             *;
*****************************************************************;
%LET DISKREPT = c:\Windows\temp\Disk_Drive_Information.txt;


*****************************************************************;
* Allocate DISK Drive information using the DRIVEMAP keyword.   *;
*****************************************************************;
filename diskinfo DRIVEMAP;


*****************************************************************;
* Allocate TEMPFILE to hold DOS commands that will be built in  *;
* the DATA step, below.                                         *;
*****************************************************************;
filename tempfile TEMP mod;


*****************************************************************;
* Input the DISK Drive names from diskinfo. Create DOS command  *
* lines (BIGLINE) and PUT them to TEMPFILE, so that they can be *;
* executed in a DATA _NULL_ step later.                         *;
*****************************************************************;
data mymap;

file tempfile;

infile diskinfo;
input drive $;

if drive in(&SKIPDEVS) then delete;

retain callsys      "call system('dir "
       slashcarrot  '\ >> '
       targetfile   "&DISKREPT'"
       leftparen    ');'
       ;

bigline = callsys || trim(left(drive)) || slashcarrot || targetfile || leftparen;

put bigline;

run;


*****************************************************************;
* INCLUDE TEMPFILE to execute the DOS commands built by the DATA*;
* step, above. They will execute a DOS "DIR" on the main direct-*;
* ory of each DISK Drive and store the results in a .txt file.  *;
*****************************************************************;
data _null_;

%INCLUDE tempfile;

run;


*****************************************************************;
* Clear TEMPFILE.                                               *;
*****************************************************************;
filename tempfile clear;


*****************************************************************;
* View the results via the FSLIST window. (Remember to close the*;
* FSLIST window if you are going to execute this again).        *;
*****************************************************************;
filename dirinfo "&DISKREPT";

proc fslist file=dirinfo;
run;

page divider
About the author:

Michael A. Raithel is a well-known, award-winning SUGI and NESUG speaker and contributor. He is the author of the Books By Users book Tuning SAS Applications in the MVS Environment, Second Edition. Michael has used SAS software as a consultant and analyst for 17 years.




These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.