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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

 

View solution in original post

8 REPLIES 8
Astounding
PROC Star
If %strong causes a problem, remove it. There's nothing about the code you have shown that requires %str.
Tom
Super User Tom
Super User

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);
Kirtid
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

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

 

Kirtid
Obsidian | Level 7
Thanks for the response again. I used %SYSLPUT too but still the libname for the windows server is not recognized and getting the same macro resolving failed error :(. I still wonder as to why it is not getting resolved.
Tom
Super User Tom
Super User

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()?

 

Kirtid
Obsidian | Level 7
Sorry, the paths that I mentioned was only a dummy path I framed to show an example(corrected them as below). When I define libname directly as below , they work perfectly fine, but problem comes only when I want to refer the libname by a macro variable.
rsubmit;
libname wlib "c:\test\myfiles" ;
endrsubmit;
Tom
Super User Tom
Super User

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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 998 views
  • 1 like
  • 3 in conversation