This program, and the concept that it illustrates, will be helpful to SAS programmers in a number of ways:
*****************************************************************; * 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; |
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.
*****************************************************************;
* 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;
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.
Type: | Sample |
Topic: | Non SAS Authors ==> Michael Raithel |
Date Modified: | 2006-01-10 03:02:51 |
Date Created: | 2004-10-11 14:28:59 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Windows | n/a | n/a |