If you work in a team environment, you might be accustomed to using mapped network drives for source data folders or to publish results. If you've recently moved to a SAS server environment, you might not have those mapped drives available. How can you tell?
This question was posted on the SAS Support Communities, and SAS Communities member Patrick provided a handy code snippet that does the trick. Patrick learned the trick himself from SAS Note 24818.
The following code uses a special DRIVEMAP device for the FILENAME statement. DRIVEMAP works only on Windows systems, which are the only systems that support the concept of mapped drives.
filename diskinfo DRIVEMAP; data _null_; infile diskinfo; input; put _infile_; run; |
Here's the output on my PC, where I have a two mapped network drives, U: and W:. (C: and D: are part of my laptop device.)
NOTE: The infile DISKINFO is: Drivemap Access Device, PROCESS,RECFM=V,LRECL=32767 C: D: U: W:
Mapped drives are typically available only from your local machine. Even if you use SAS on a remote Windows server, the process that defines the mapped drive aliases is usually not triggered when you connect. If this is the case for you, you'll have to adjust your process to use UNC path notation (example: "\\server\folder\project" instead of the familiar "P:\project" shortcut). (Additional note for SAS admins: on a Windows SAS server, you must mark the server machine as Trusted for Delegation to allow end users to access these network paths.)
If you've moved from a local PC version of SAS to a remote non-Windows server (these days, Linux is common), then I'm afraid that "mapped drives" are a lost concept. You'll need to change your code to use Unix-style paths. A SAS admin or Unix-admin might need to help you to find the correct locations.
6 Comments
That's nifty, Chris. Too bad it doesn't show the UNC for the mapped drives. Assume this works even without XCMD turned on? For those who do have XCMD, an alternative which does give the UNC is: filename diskinfo pipe "net use" ;
I thought it might be handy to write a %GetUNC function-style macro, it turns out Art Carpenter has already written one: http://www2.sas.com/proceedings/forum2008/023-2008.pdf. : )
"The Path, the Whole Path, and Nothing But the Path, So Help Me Windows" -- a great title. And a nice throwback to the CALL MODULE and SASCBTBL methods, which I documented as part of the Windows SAS companion after Rick Langston released the methods in SAS V6.11 (1995).
Hi Chris,
I had a similar task to solve some time ago, I also used PIPE (same as Quentin) but instead "net ues" I used windows's wmic command: "wmic logicaldisk get name, description" which gave me not only drive letter but also its description.
Code like that:
filename diskinfo PIPE "wmic logicaldisk get name, description";
data _null_;
infile diskinfo;
input;
if index(_INFILE_,":") then put _infile_;
run;
returned:
Local Fixed Disk C:
Local Fixed Disk D:
Removable Disk G:
Good tip! That works great locally when you have XCMD privileges. DRIVEMAP is less detailed, but doesn't need to XCMD privileges (I think...). In practice it won't make so much of a difference, as mapped drives are most relevant for users of local SAS. When connecting to a remote session (where XCMD might be disabled), mapped drives are probably not used.
We've got a Linux install with a few 'bi-' drives (accessible both to Windows and Linux), so I put this macro together :
So with this global variable:
%let DRIVES = /mnt/nfs/prod/Teams/statutory/REGREP;
I can do this:
%let urlfile=%conv2url(S:\_Louisiana\173Report\Vendor_Files\Transportation\Report-1017.xlsx);
%put &=urlfile;
And get this:
URLFILE=/mnt/nfs/prod/Teams/statutory/REGREP/_Louisiana/173Report/Vendor_Files/Transportation/Report-1017.xlsx
And then I can do a proc import on that file, for example.
Or someone can enter the S: path and filename and the macro will convert it for them.
Wow, that's some macro!