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?
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.
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.
Thank you
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.