BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SteveNZ
Obsidian | Level 7

Hi all,

I have a program that outputs excel files to a mapped drive but not all users of the program remember to map to the drive before running the program.

I've found the following script on the net that automatically maps to the drive so my question is can I package this so it runs directly from SAS?

Ideally I'd like it in a macro that picks up the users username and password. Script that works is:

Dim objNetwork

Set objNetwork = WScript.CreateObject("WScript.Network")

strLocalDrive = "E:"

strUser = "userA"

strPassword = "passwordA"

strRemoteShare = "\\SERVER\etc\etc"

objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, False

Any help really appreciated.

regards

Steve,

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

This works for me to map my personal network folder to the J: drive letter.

The syntax might be different if you are using a different operating system.

1    data _null_;

2       infile 'net use J: \\mopcitnas05\%username%$' pipe ;

3       input;

4       put _infile_;

5    run;

NOTE: The infile 'net use J: \\mopcitnas05\%username%$' is:

      Unnamed Pipe Access Device,

      PROCESS=net use J: \\mopcitnas05\%username%$,

      RECFM=V,LRECL=256

The command completed successfully.

NOTE: 2 records were read from the infile 'net use J: \\mopcitnas05\%username%$'.

      The minimum record length was 0.

      The maximum record length was 35.

NOTE: DATA statement used (Total process time):

      real time           5.22 seconds

      cpu time            0.06 seconds

View solution in original post

7 REPLIES 7
data_null__
Jade | Level 19

Yes you can call that script from within SAS.

However can't you just define a FILEREF using the same syntax \\SERVER\etc\etc.

SteveNZ
Obsidian | Level 7

Would that work? I assumed the drive would have to be mapped. Do you have any sample code that uses username and passwords?

I'd rather use the filenale statement as I've discovered a few hooks in the above script since posting.

data_null__
Jade | Level 19

No I don't have to use passwords.  Give it a try and see what happens.

Hopefully someone will come along with more info.  There is also the online docs. Smiley Happy

Tom
Super User Tom
Super User

First fix the program to write to whatever the user tells it to write to instead of assuming there is E: drive mapped.  What do users with 5 or more physical drives on their PCs do?  In your example you should be able to replace a path like "E:\myoutput.xls" with "\\SERVER\etc\etc\myoutput.xls".

Otherwise why not just use the net use (net use - Wikipedia, the free encyclopedia) command from the command prompt to map the drive instead of the VBS function call?  Is there something special about this drive that requires you to supply username and password?  Normally drives should just use the username and password of the user that is trying to connect to them.  If that works for you then you can use the system() function %SYSEXEC macro command or a filename with PIPE option to run the net use command from within your SAS program.

SteveNZ
Obsidian | Level 7

Hi @Tom,

Do you have an example I could adapt? I've never needed to look at this area before so am unfamiliar with code required.

Another option I thought of is using the drivemap option to see if the drive is mapped and, if not, sound an alert and not produce the files. I can easily do that but would prefer to get SAS to map the drive for the user.

cheers

Tom
Super User Tom
Super User

This works for me to map my personal network folder to the J: drive letter.

The syntax might be different if you are using a different operating system.

1    data _null_;

2       infile 'net use J: \\mopcitnas05\%username%$' pipe ;

3       input;

4       put _infile_;

5    run;

NOTE: The infile 'net use J: \\mopcitnas05\%username%$' is:

      Unnamed Pipe Access Device,

      PROCESS=net use J: \\mopcitnas05\%username%$,

      RECFM=V,LRECL=256

The command completed successfully.

NOTE: 2 records were read from the infile 'net use J: \\mopcitnas05\%username%$'.

      The minimum record length was 0.

      The maximum record length was 35.

NOTE: DATA statement used (Total process time):

      real time           5.22 seconds

      cpu time            0.06 seconds

SteveNZ
Obsidian | Level 7

Hi all,

Tom's idea worked ie:

data _null_;
   infile 'net use E: \\SERVER\etc\etc /user:username password' pipe ;
   input;
   put _infile_;

    run;

Thanks for all the help

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 3941 views
  • 3 likes
  • 3 in conversation