5
votes

I've got a macro that I've created on my local machine in a .sas file. I've also got a local dataset that have been using to test the macro. This dataset has the same descriptors as a remote dataset, but just less observations. Now, I'm trying to run my local macro against the remote dataset. Here is basically what I have:

This works as expected:

%include "C:\my_sas_macro.sas";

%my_sas_macro(my_data=work.localdata)

but then this generates an error (error follows):

%include "C:\my_sas_macro.sas";

rsubmit;
%my_sas_macro(my_data=remotelib.remotedata)
endrsubmit;

The log with error:

125  %include "C:\my_sas_macro.sas";
136
137  rsubmit;
NOTE: Remote submit to REMOTEID.__7551 commencing.
WARNING: Apparent invocation of macro MY_SAS_MACRO not resolved.
83   %my_sas_macro(my_data=remotelib.remotedata)
     -
     180
ERROR 180-322: Statement is not valid or it is used out of proper order.
84   endrsubmit;

NOTE: Remote submit to REMOTEID.__7551 complete.

I'm pretty sure I need to somehow transfer the %macro/%mend block over to the server, but I can't figure out how. I've seen the %SYSLPUT but that is for macro variables and not full macros.

Is there anyway that I can run my macro on the server without having to just SSH over the code and %include it there?

Thanks!

[Edit] Implemented Solution

So based on @CarolinaJay65 's answer I came up with the following macro which is working pretty well for me so far.

%macro include_on_server(file=);
%let server_file = ~/temp.sas;
%SYSLPUT macro_file=&file;
%SYSLPUT server_file = &server_file;

rsubmit;

proc upload
    infile= "&macro_file."
    outfile= "&server_file."
; run;

%include "&server_file.";
endrsubmit;

%mend include_on_server;

This allows me to just call %include_on_server(file="C:\my_file.sas") and then it's now included in my remote session.

3

3 Answers

6
votes

How about using Proc Upload

 rsubmit;
 Proc Upload
  infile='C:\my_sas_macro.sas'
  outfile='//server/my_sas_macro.sas' ;
 run;

 %include '//server/my_sas_macro.sas';
 %my_sas_macro(my_data=remotelib.remotedata)

or you could assign the entire macro to a macro variable then use %syslput

1
votes

You have a few options, one of which being CarolinaJay's suggestion. Another is if you don't mind doing the processing locally, you can use a LIBNAME to refer to the server library:

libname server= slibref=; so libname myserver server=unix slibref=work;

if your server is named 'unix' in the connect script and you want its work directory.

PROC CATALOG, or I think also PROC COPY, can be used in conjunction with a server libref like above to copy the code, either as a macro or simply as source code. Macros are stored in a catalog (SASMACR), which can be copied from one libref to another (in this case from one machine to another). You could also store the source to create the macro in a catalog and move that, preventing you from having to compile the macro. This does require the catalogs to be compatible, though, which depends on the type of OS you are running on the server versus your local machine.

Finally, you can follow the suggestions in this paper: http://www.nesug.org/proceedings/nesug05/io/io2.pdf which combines the catalog solution and PROC UPLOAD together to allow even non-compatible machines to work together.

1
votes

Put an rsubmit/endrsubmit inside the include, around the macro definition. When you include the local file, it will the complile the macro remotely.

EDIT:

i.e.

c:\remote_macro.sas contains the below :

rsubmit ;
  %MACRO MYMACRO ;
    /* do stuff */
  %MEND ;

  %MACRO ANOTHERMACRO(PARAM) ;
    /* Do other things */
    %PUT &PARAM ;
  %MEND ;
endrsubmit ;

Then run the following in SAS :

%inc "c:\remote_macro.sas" ;

rsubmit ;
  %MYMACRO ;
  %ANOTHERMACRO(Hello World) ;
endrsubmit ;