Hello,
I want to transfer a dataset from host to windows server. I use a customized macro that creates a connection between the host and the windows server. The problem is that I define the windows server path via a macro variable as below -
%let test = %str(Libname librer "test/path/on/windows");
&test;
I have some validations to be done on host server prior connecting to windows, so I will have to pass the above lines in macro call, but since I pass the libname reference using %str, I get an error that the lib name can't be resolved.
Could someone please assist me here.
Thanks in advance.
KK
So build it slowly. First check if you can actually set a macro variable in the remote session and return it to the local session.
%syslput rvar=This is remote variable value;
rsubmit;
%sysrput lvar=&rvar;
endrsubmit;
%put &=lvar;
Also try removing so much macro code from the problem. For example you can make a libref using the LIBNAME statement in a data step.
rsubmit;
data _null_;
rc=libname('wlib',"c:\test\myfiles") ;
put rc=;
run;
endrsubmit;
You can reference a macro variable in a data step using the SYMGET() function.
%syslput path=c:\test\myfiles;
rsubmit;
data _null_;
rc=libname('wlib',symget('path'));
put rc=;
run;
endrsubmit;
Why did you wrap that string inside of %STR()? What is it that you are trying to protect from the macro processor?
%let test = libname librer "test/path/on/windows" ;
&test;
What is it that you are actually doing, it is hard to tell from your explanation. Can you present a simplified piece of code that replicates the issue?
If you just want to remove macro quoting from a macro variable's value use the %UNQUOTE() function.
%unquote(&test);
Thanks for the response. I can't mention the libname statement directly in the macro without passing it through %str, as my process would comment out all the libname at the end, so that's why I want to mask the libname.
The resolving of libname fails online the below case, since the %str does not work when called inside the macro %upload.
%macro host_check;
%if %sysfuncn(libref(hostlib)) = 0 %then
%upload;
%mend host_check;
%macro upload;
rsubmit;
%let libws = %str(libname wlib "test/path/on/windows");
&libws;
proc upload inlib=hostlib outlib=wlib;
select <dataset>;
quit;
endrsubmit;
signoff;
Error message:
"
&libws
-
Apparent symbolic reference libws is not resolved
Error 180-322 Statement is not valid or it is used out of proper order.
"
Kindly assist.
I don't get how the %STR() helps solve the problem you described.
You want the macro variable defined on the remote machine, not on the local machine where the %UPLOAD macro is running.
Try the %SYSLPUT function.
%macro upload;
signon;
%syslput libws = libname wlib "test/path/on/windows" ;
rsubmit;
&libws;
proc upload inlib=hostlib outlib=wlib;
select <dataset>;
quit;
endrsubmit;
signoff;
%mend upload;
If you have trouble using %SYSLPUT inside of a macro then try using the old style method of pushing macro variable definitions to remote process. https://github.com/sasutils/macros/blob/master/syslput612.sas
Please be more specific about the error.
Start by running code without any macro variables or macros.
Does this work? That path does not look valid. Why would you call it "path on windows" and / instead \ as the delimiter between folders? Why does it not start with / or drive letter or \\server ?
rsubmit;
libname wlib "test/path/on/windows" ;
endrsubmit;
Perhaps you just need %nrstr() instead of %str()?
So build it slowly. First check if you can actually set a macro variable in the remote session and return it to the local session.
%syslput rvar=This is remote variable value;
rsubmit;
%sysrput lvar=&rvar;
endrsubmit;
%put &=lvar;
Also try removing so much macro code from the problem. For example you can make a libref using the LIBNAME statement in a data step.
rsubmit;
data _null_;
rc=libname('wlib',"c:\test\myfiles") ;
put rc=;
run;
endrsubmit;
You can reference a macro variable in a data step using the SYMGET() function.
%syslput path=c:\test\myfiles;
rsubmit;
data _null_;
rc=libname('wlib',symget('path'));
put rc=;
run;
endrsubmit;
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.