How to list your mapped drives in a SAS program


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;
  put _infile_;

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,

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.


About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies
He also hosts the SAS Tech Talk webcasts each year from SAS Global Forum, connecting viewers with smart people from SAS R&D and the impressive work that they do.

Related Posts


  1. 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: : )

    • Chris Hemedinger
      Chris Hemedinger on

      "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).

  2. 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;
    if index(_INFILE_,":") then put _infile_;

    Local Fixed Disk C:
    Local Fixed Disk D:
    Removable Disk G:

    • Chris Hemedinger
      Chris Hemedinger on

      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.

Leave A Reply

Back to Top