%SYSLPUT Statement

Creates a single macro variable in the server session or copies a specified group of macro variables to the server session.
Valid in: client session

Syntax

Form 1:

%SYSLPUT macro-variable=value </REMOTE=server-ID> ;

Form 2:

%SYSLPUT _ALL_ | _AUTOMATIC_ | _GLOBAL_ | _LOCAL_ | _USER_
</LIKE=‘character-string’><REMOTE=server-ID>;

Syntax Description

_ALL_
copies all user-generated and automatic macro variables to the server session.
_AUTOMATIC_
copies all automatic macro variables to the server session. The automatic variables copied depend on the SAS products installed at your site and on your operating system. The scope is identified as AUTOMATIC.
_GLOBAL_
copies all user-generated global macro variables to the server session. The scope is identified as GLOBAL.
/LIKE=<‘character-string’ >
Specifies a subset of macro variables whose names match a user-specified character sequence, or pattern. Only this identified group of variables with names matching the pattern will be copied to the server session.
Note: The LIKE= option is not case sensitive.
‘character-string’
Specifies the sequence of characters, or pattern, to be used as the criteria for determining which macro variables are to be copied to the server session. Character patterns can consist of the following:
  • any sequence of characters, A-Z
  • any sequence of digits, 0-9
  • a single wildcard character in the form of an asterisk (*)
The wildcard character (*) cannot be embedded or used more than once in the character string. The examples below illustrate how the LIKE= option works with the wildcard character. For these examples, assume that the following macro variables are defined in the client session: rc1, rc2, unixHost, and winHost:
like='rc*';
Wildcard at the end:
returns rc1 and rc2.
like='*Host';
Wildcard at the beginning:
returns unixHost and winHost.
like='*host';
Wildcard at the beginning and lower cased “h” in name:
returns unixHost and winHost.
like='r*c';
Wildcard in the middle:
is not valid and returns a syntax error.
like='*rc*';
More than one wildcard (at beginning and end):
is not valid and returns a syntax error.
like='rc';
Wildcard not specified:
returns nothing (no match)
like=' ';
Wildcard not specified and ‘character-string’ is empty:
returns nothing (no macro variables are copied)
Restrictions:The wildcard (*) cannot be embedded in the character-string.

The wildcard (*) can only be specified once in the character-string.

Requirement:The wildcard (*) must be used at either the beginning or the end of the character-string.
Interaction: The /REMOTE= and /LIKE= options are independent of each other and can be specified on the same %SYSLPUT statement, regardless of order.
Notes:Macro variables in the same server session are over-written each time they are submitted.

Read-only system options in the remote server are not over written.

Tip:To copy all macro variables to the server session without specifying LIKE= , use the _ALL_ special word in the %SYSLPUT statement.
_LOCAL_
copies all user-generated local macro variables to the server session. The scope is the name of the currently executing macro.
macro-variable
specifies the name of a macro variable to be created in the server session.
value
specifies the macro variable reference, a macro invocation, or the character value to be assigned to the server macro-variable. The character value should not contain nested quotation marks.
Requirement:Values containing special characters, such as the front slash (/) or single quotation mark (‘), must be masked using the %BQUOTE function so that the macro processor correctly interprets the special character as part of the text and not as an element of the macro language. See Masking Character Values with %BQUOTE (Form 1) for an example of how to use the %BQUOTE function. For more information on Macro Quoting in general, see Macro Quoting in SAS Macro Language: Reference.
/REMOTE=server-ID
specifies the name of the server session that the macro variable will be created in. If only one server session is active, the server-ID can be omitted. If multiple server sessions are active, omitting this option causes the macro to be created in the most recently accessed server session. You can find out which server session is currently active by examining the value that is assigned to the CONNECTREMOTE system option.
Interactions:The /REMOTE= option that is specified in the %SYSLPUT macro statement overrides the CONNECTREMOTE= system option.

The /REMOTE= and /LIKE= options are independent of each other and can be specified on the same %SYSLPUT statement, regardless of order.

_USER_
copies all user-generated global and local macro variables to the server session. The scope is identified either as GLOBAL, or as the name of the macro in which the macro variable is defined.

Details

%SYSLPUT Macro Statement

The %SYSLPUT statement is a macro statement used in SAS/CONNECT that allows you to do the following:
  • create a new macro variable in the server session and assign it a value from the client session (form 1).
  • copy a specified group of existing macro variables and their values from the client to the server session (form 2).
Note: Unlike the %SYSRPUT statement that is submitted within the RSUBMIT block of code and processed in the server session, the %SYSLPUT statement is submitted outside the RSUBMIT code block and processed in the client session.

Creating a Single Macro Variable to Be Used in the Server Session (Form 1)

The %SYSLPUT statement is a macro statement that is submitted in the client session to create and assign a value to a macro variable in the server session.
If you are signed on to multiple server sessions, %SYSLPUT submits the macro assignment statement to the most recently used server session. If you are signed on to only one server session, %SYSLPUT submits the macro assignment statement to that server session. If you are not signed on to any session, an error condition results.

Copying a Group of Macro Variables (Form 2)

The %SYSLPUT statement also allows you to copy a specified group of existing macro variables from the client to the server session. The arguments used with this form allow you to define the group of macro variables to be copied based on variable type (automatic or user-defined), variable scope (global or local), and variable name. To copy all macro variables, regardless of type, scope, or name, use the _ALL_ argument in the %SYSLPUT statement.
You can also use the AUTOSIGNON system option with the %SYSLPUT statement to automatically sign on to a server session and copy specified macro variables to that server session. When the %SYSLPUT statement is specified with the AUTOSIGNON system option, the RSUBMIT command or statement automatically executes a sign-on and honors all macro variables defined in the %SYSLPUT statement for that session. For an example of using the AUTOSIGNON system option with the %SYSLPUT macro statement, see Using %SYSLPUT with the AUTOSIGNON Option. For more information about the AUTOSIGNON system option, see AUTOSIGNON System Option.

Examples

Example 1: Creating a Macro Variable with %SYSLPUT (Form 1)

This example creates the macro variable FLAG in the current server session and assigns to it a value of 1.
%syslput flag=1;

Example 2: Using the Macro Statement with %SYSLPUT (Form 1)

%SYSLPUT enables you to dynamically assign values to variables that are used by macros that are executed in a server session. The macro statement %SYSLPUT is used to create the macro variable REMID in the server session and to use the value of the client macro variable RUNID. The REMID variable is used by the %DOLIB macro, which is executed in a server session, to find out which operating system-specific library assignment should be used in the server session.
Using %SYSLPUT To Find Out Which Libraries Can be Used in the Server Session
%macro assignlib (runid);
   signon rem&runid;
   %syslput remid=&runid;
   rsubmit rem&runid;
      %macro dolib;
         %if (&remid eq 1) %then %do;
            libname mylib 'h:';
            %end;
         %else %if (&remid eq 2) %then %do;
            libname mylib '/afs/some/unix/path';
            %end;
      %mend;
      %dolib;
   endrsubmit;
%mend;

Example 3: Masking Character Values with %BQUOTE (Form 1)

Since the forward slash is a macro language special character that has a special meaning to the macro processor, using it in the %SYSLPUT statement, either directly or indirectly (as a macro variable reference), will cause an error to be generated. This example uses the %BQUOTE function around the macro variable reference &pathineed, to mask the front slashes in a UNIX pathname.
Using %BQUOTE To Mask Character Values That Are Used in a %SYSLPUT Statement
  %let pathineed=/abc/xyz;
  %syslput pathineed=%bquote(&pathineed);
  rsubmit;
NOTE: Remote submit to computer commencing.
  %put &pathineed
  endrsubmit;
 %put &pathineed /abc/xyz
NOTE: Remote submit to computer complete.

Example 4: Copying a Group of Variables to the Server Session (Form 2)

This example uses _ALL_ in the %SYSLPUT statement to copy two macro variables, rc1 and rc2, to the server session. The %PUT statement in the RSUBMIT block uses variable references, &rc1 and &rc2, to display these variables and their values in the SAS log. When the %PUT statements execute, the macro processor resolves the expressions rc1=&rc1 and rc2=&rc2 to rc1=rem1 and rc2=rem2, respectively, and displays them in the SAS log.
%let rc1=rem1;
%let rc2=rem2;

%syslput _all_; 
rsubmit host;      
   %put rc1=&rc1
   %put rc2=&rc2
endrsubmit; 

Example 5: Specifying a Group of Variables Using LIKE= (Form 2)

By specifying _USER_ followed by LIKE=’rc*’ in the %SYSLPUT statement below, only the user-defined macro variables whose names begin with the letters “rc” are copied to the server session. Since the macro variable unixHost does not meet the pattern-matching criteria, it is not recognized by the %PUT statement in the server session and a warning is displayed in the log. The %PUT statements cause the expressions rc1=&rc1 and rc2=&rc2 to be displayed as rc1=rem1 and rc2=rem2 in the SAS log.
signon foo sascmd="sas";
   %let rc1=rem1;
   %let rc2=rem2;
   %let unixHost=rem3;

   %syslput _user_/like='rc*' remote=host; 
   rsubmit host;
      %put rc1=&rc1              /* writes rc1=rem1 to the log  */
      %put rc2=&rc2              /* writes rc2=rem2 to the log  */  
      %put unixHost=&unixHost;   /* generates WARNING: Apparent symbolic  */ 
                                 /*  reference UNIXHOST not resolved.     */ 
   endrsubmit;

Example 6: Overwriting Variables in the Same Server Session (Form 2)

signon foo sascmd="sas";      
%let rc1=rem1;
%syslput _global_/like='rc*' remote=host;        
rsubmit host;
   %put rc1=&rc1     
endrsubmit;

 %let rc1=changeValue;

 rsubmit host;
    %put rc1=&rc2
 endrsubmit;

Example 7: Using %SYSLPUT with the AUTOSIGNON Option

options autosignon=yes sascmd="sas";
%let rc1=rem1;
%let rc2=rem2;
%syslput _global_/like='rc*' remote=host;

Example 8: Using %SYSLPUT with the AUTOSIGNON Option in Multi-task Processes

options autosignon;
options sascmd="sas";
%let rc1=rem1;
%let rc2=rem2;
%let trc1=test1;
%let trc2=test2;
%syslput _global_/like='rc*' remote=host1;
%syslput _global_/like='trc*' remote=host2;
Rsubmit host1;
   %put rc1=&rc1;
   %put rc2=&rc2;
Endrsubmit;
Rsubmit host2;
   %put trc1=&trc1;
   %put trc2=&trc2;
Endrsubmit;