- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
rsubmit;
libname wlib "c:\test\myfiles" ;
endrsubmit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;