Chapter Contents

Previous

Next
SAS Companion for the CMS Environment

Accessing System Variables

Under CMS, SAS provides a mechanism for accessing system variables that have been created with the CMS GLOBALV command. You can access GLOBALV variables directly from SAS by using either the %SYSGET macro function or the SYSGET DATA step function. SAS also provides the SET= system option to create or change system variables from within a SAS session.

The group name and variable name can be any that are valid for the CMS GLOBALV command (see the VM/ESA CMS Command Reference). If you omit the group name, the variable is extracted from the group SAS if it is found there, or else from the default group UNNAMED. If the variable has not been set by GLOBALV, SYSGET or %SYSGET returns an error.

SYSGET uses the EXECCOMM interface and therefore the length of the variable name is limited to 250 characters. GLOBALV imposes a maximum length of 255 characters on the variable's value. The full length is returned by SYSGET or %SYSGET if the SAS variable is assigned a sufficient length. Otherwise the value that is returned by SYSGET or %SYSGET is truncated to the SAS variable's length, which is 200 characters by default.

CAUTION:
Using SYSGET or %SYSGET can replace the value of an existing variable in your SAS EXEC. SYSGET and %SYSGET use the EXECCOMM interface, which assigns variables in the SAS EXEC. If the variable that you assign with SYSGET or %SYSGET has the same name as an existing variable in the currently active EXEC, the existing variable receives the value that is specified by SYSGET or %SYSGET. This change to a global variable could adversely affect other aspects of your SAS session.  [cautionend]


Using the SYSGET DATA Step Function

When you use the SYSGET DATA step function to access system variables, you must enclose the string that specifies the group name and the variable name in single quotes:

SYSGET('group-name variable-name')

For example, if the group name is MINE and the variable name is TIME, your DATA step might look like this:

data test;
   x=sysget('mine time');
   . . . more data lines . . .
run;


Using the %SYSGET Macro Function

When you use the %SYSGET macro function to access system variables, do not enclose the string that specifies the group name and the variable name in single quotes:

%SYSGET(group-name variable-name)

For example, if the group name is MINE and the variable name is TIME, your code might look like this:

%let x=%sysget(mine time);


Using the SET= System Option

The SET= system option may be used to set a system variable from within your SAS session, using the following syntax in an OPTIONS statement:

OPTIONS SET='<group-name> variable-name=value'
The following example assigns the value of NOW to the variable TIME in the group MINE:

options set='mine time=now';
run;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.