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

Hi,

I need to get UNC path for a mapped drive as different users have their HOME drive on different servers.

I use the getUNC macro from the really good paper “The Path, The Whole Path, And Nothing But the Path, So Help Me Windows” by Arthur L. Carpenter (http://www2.sas.com/proceedings/forum2008/023-2008.pdf).

 

 

%MACRO getUNC ;
DATA _NULL_;
length input_dir $200 output_dir $200;
* The input directory can only be a drive letter + colon ONLY e.g. j: ;
input_dir = 'h:';
output_dir = ' ';
output_len = 200;
call module("WNetGetConnectionA", input_dir, output_dir, output_len);
call symputx('dir',input_dir,'l');
call symputx('path',output_dir,'l');
RUN;
%put drive letter is &dir;
%put path is &path;
%MEND getunc;

%getunc;

 

But get following error:

NOTE: Invalid argument to function MODULE('WNetGetConne'[12 of 18 characters shown],'h:

        '[12 of 200 characters shown],'            '[12 of 200 characters shown],200) at line

      1 column 186.

input_dir=h: output_dir=  output_len=200 _ERROR_=1 _N_=1

 

I am on Window 10 and use SAS 9.4

 

Can anyone see what is going wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

I tried to copy/paste the code in the document and the problem occurred as you described.

It appeared that the copy/paste has concatenated two arguments of the routine instruction :

 

STACKPOP=CALLEDRETURNS=LONG

 

instead of

 

STACKPOP=CALLED RETURNS=LONG

 

Adding a space solved the problem.

View solution in original post

3 REPLIES 3
gamotte
Rhodochrosite | Level 12

Hello,

 

I tried to copy/paste the code in the document and the problem occurred as you described.

It appeared that the copy/paste has concatenated two arguments of the routine instruction :

 

STACKPOP=CALLEDRETURNS=LONG

 

instead of

 

STACKPOP=CALLED RETURNS=LONG

 

Adding a space solved the problem.

alr
Quartz | Level 8 alr
Quartz | Level 8

Thank you

alr
Quartz | Level 8 alr
Quartz | Level 8

So the complete working code is:

 

FILENAME SASCBTBL CATALOG "work.temp.attrfile.source";
 
DATA _NULL_;
FILE SASCBTBL;
    PUT "ROUTINE WNetGetConnectionA MODULE=MPR MINARG=3 MAXARG=3 STACKPOP=CALLED RETURNS=LONG;";
    PUT "  ARG 1 CHAR INPUT BYADDR FORMAT=$CSTR200.;";
    PUT "  ARG 2 CHAR UPDATE BYADDR FORMAT=$CSTR200.;";
    PUT "  ARG 3 NUM UPDATE BYADDR FORMAT=PIB4.;";
RUN;


%MACRO getUNC ;
DATA _NULL_;
length input_dir $200 output_dir $200;
* The input directory can only be a drive letter + colon ONLY e.g. j: ;
input_dir = 'h:';
output_dir = ' ';
output_len = 200;
call module("WNetGetConnectionA", input_dir, output_dir, output_len);
call symputx('dir',input_dir,'l');
call symputx('path',output_dir,'l');
RUN;
%put drive letter is &dir;
%put path is &path;
%MEND getunc;

%getunc;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3041 views
  • 1 like
  • 2 in conversation