Chapter 14

Automatic Macro Variables

Automatic Macro Variables

Dictionary

SYSADDRBITS Automatic Macro Variable

SYSBUFFR Automatic Macro Variable

SYSCC Automatic Macro Variable

SYSCHARWIDTH Automatic Macro Variable

SYSCMD Automatic Macro Variable

SYSDATASTEPPHASE Automatic Macro Variable

SYSDATE Automatic Macro Variable

SYSDATE9 Automatic Macro Variable

SYSDAY Automatic Macro Variable

SYSDEVIC Automatic Macro Variable

SYSDMG Automatic Macro Variable

SYSDSN Automatic Macro Variable

SYSENCODING Automatic Macro Variable

SYSENDIAN Automatic Macro Variable

SYSENV Automatic Macro Variable

SYSERR Automatic Macro Variable

SYSERRORTEXT Automatic Macro Variable

SYSFILRC Automatic Macro Variable

SYSHOSTINFOLONG Automatic Macro Variable

SYSHOSTNAME Automatic Macro Variable

SYSINDEX Automatic Macro Variable

SYSINFO Automatic Macro Variable

SYSJOBID Automatic Macro Variable

SYSLAST Automatic Macro Variable

SYSLCKRC Automatic Macro Variable

SYSLIBRC Automatic Macro Variable

SYSLOGAPPLNAME Automatic Macro Variable

SYSMACRONAME Automatic Macro Variable

SYSMENV Automatic Macro Variable

SYSMSG Automatic Macro Variable

SYSNCPU Automatic Macro Variable

SYSNOBS Automatic Macro Variable

SYSODSESCAPECHAR Automatic Macro Variable

SYSODSPATH Automatic Macro Variable

SYSPARM Automatic Macro Variable

SYSPBUFF Automatic Macro Variable

SYSPROCESSID Automatic Macro Variable

SYSPROCESSMODE Automatic Macro Variable

SYSPROCESSNAME Automatic Macro Variable

SYSPROCNAME Automatic Macro Variable

SYSRC Automatic Macro Variable

SYSSCP and SYSSCPL Automatic Macro Variables

SYSSCPL Automatic Macro Variable

SYSSITE Automatic Macro Variable

SYSSIZEOFLONG Automatic Macro Variable

SYSSIZEOFPTR Automatic Macro Variable

SYSSIZEOFUNICODE Automatic Macro Variable

SYSSTARTID Automatic Macro Variable

SYSSTARTNAME Automatic Macro Variable

SYSTCPIPHOSTNAME Automatic Macro Variable

SYSTIME Automatic Macro Variable

SYSTIMEZONE Automatic Macro Variable

SYSTIMEZONEIDENT Automatic Macro Variable

SYSTIMEZONEOFFSET Automatic Macro Variable

SYSUSERID Automatic Macro Variable

SYSVER Automatic Macro Variable

SYSVLONG Automatic Macro Variable

SYSVLONG4 Automatic Macro Variable

SYSWARNINGTEXT Automatic Macro Variable

Automatic Macro Variables

Automatic macro variables are created by the macro processor and they supply a variety of information. They are useful in programs to check the status of a condition before executing code.

Dictionary

SYSADDRBITS Automatic Macro Variable

Contains the number of bits of an address.

Type:

Automatic macro variable (read only)

Details

The SYSADDRBITS automatic macro variable contains the number of bits needed for an address.

SYSBUFFR Automatic Macro Variable

Contains text that is entered in response to a %INPUT statement when there is no corresponding macro variable.

Type:

Automatic macro variable (read and write)

Details

Until the first execution of a %INPUT statement, SYSBUFFR has a null value. However, SYSBUFFR receives a new value during each execution of a %INPUT statement, either the text entered in response to the %INPUT statement where there is no corresponding macro variable or a null value. If a %INPUT statement contains no macro variable names, all characters entered are assigned to SYSBUFFR.

Example: Assigning Text to SYSBUFFR

This %INPUT statement accepts the values of the two macro variables WATRFALL and RIVER:

%input watrfall river;

If you enter the following text, there is not a one-to-one match between the two variable names and the text:

Angel Tributary of Caroni

For example, you can submit these statements:

%put WATRFALL contains: *&watrfall*;
%put RIVER contains: *&river*;
%put SYSBUFFR contains: *&sysbuffr*;

After execution, they produce this output in the SAS log:

WATRFALL contains: *Angel*
RIVER contains: *Tributary*
SYSBUFFR contains: * of Caroni*

As the SAS log demonstrates, the text stored in SYSBUFFR includes leading and embedded blanks.

SYSCC Automatic Macro Variable

Contains the current condition code that SAS returns to your operating environment (the operating environment condition code).

Type:

Automatic macro variable (read and write)

Details

SYSCC is a read and write automatic macro variable that enables you to reset the job condition code and to recover from conditions that prevent subsequent steps from running.

A normal exit internally to SAS is 0. The host code translates the internal value to a meaningful condition code by each host for each operating environment. &SYSCC of 0 at SAS termination is the value of success for that operating environment’s return code.

The following are examples of successful condition codes:

Table 14.1 SYSCC Operating Environments and Values

Operating Environment

Value

z/OS

RC 0

OpenVMS

$STATUS = 1

The method to check the operating environment return code is host dependent.

The warning condition code in SAS sets &SYSCC to 4.

Note: When the ERRORCHECK= SAS system option is set at NORMAL, the value of SYSCC will be 0 even if an error exists in a LIBNAME or FILENAME statement, or in a LOCK statement in SAS/SHARE software. The value of SYSCC will also be 0 when the %INCLUDE statement fails due to a nonexistent file. For more information, see the “ERRORCHECK= System Option” in SAS System Options: Reference.

SYSCHARWIDTH Automatic Macro Variable

Contains the character width value.

Type:

Automatic macro variable (read only)

Details

The character width value is either 1 (narrow) or 2 (wide).

SYSCMD Automatic Macro Variable

Contains the last unrecognized command from the command line of a macro window.

Type:

Automatic macro variable (read and write)

Details

The value of SYSCMD is null before each execution of a %DISPLAY statement. If you enter a word or phrase on the command line of a macro window and the windowing environment does not recognize the command, SYSCMD receives that word or phrase as its value. This method is the only way to change the value of SYSCMD, which otherwise is a read-only variable. Use SYSCMD to enter values on the command line that work like user-created windowing commands.

Example: Processing Commands Entered in a Macro Window

The macro definition START creates a window in which you can use the command line to enter any windowing command. If you enter an invalid command, a message informs you that the command is not recognized. When you type QUIT on the command line, the window closes and the macro terminates.

%macro start;
  %window start
     #5  @28 'Welcome to the SAS System'
     #10  @28 'Type QUIT to exit';
  %let exit = 0;
  %do %until (&exit=1);
     %display start;
     %if &syscmd ne %then %do;
        %if %upcase(&syscmd)=QUIT %then %let exit=1;
        %else %let sysmsg=&syscmd not recognized;
     %end;
  %end;
%mend start;

SYSDATASTEPPHASE Automatic Macro Variable

Indicates the current running phase of the DATA step.

Type:

Automatic macro variable (read only)

Details

Macros are designed to only execute during the compilation of a DATA step or during the execution of a DATA step. The new automatic macro variable SYSDATASTEPPHASE ensures that the macro is being executed as part of the proper phase of a DATA step.

The value of SYSDATASTEPPHASE automatic macro variable indicates the current active phase of the DATA step. When the DATA step is not active, the value of SYSDATASTEPPHASE is null. The following are possible values of SYSDATASTEPPHASE automatic macro variable :

• INITIALIZATION

• COMPILATION

• RESOLUTION

• EXECUTION

• AUTO-LOADING STORED PROGRAM

• COMPILATION — STORED PROGRAM LOADING

• LOADING STORED PROGRAM

• AUTO-SAVING STORED PROGRAM

• SAVING STORED PROGRAM

Any non-null value, other than EXECUTION, should be considered as part of the DATA step compilation process.

Examples

Example 1: EXECUTION Phase

24  data null;
25     x=1;
26     /* Placing the argument in single quote marks delays the   */
27     /* evaluation until after the DATA step has been compiled. */
28     call execute('%put &sysdatastepphase;'),
29     put x=;
30  run;
EXECUTION
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

x=1

Example 2: COMPILATION Phase

1          data null;
2             call symput("phase", "&sysdatastepphase");
3          run;

NOTE: The data set WORK.NULL has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


4
5          %put &=phase;
PHASE=COMPILATION

SYSDATE Automatic Macro Variable

Contains the date that a SAS job or session began executing.

Type:

Automatic macro variable (read only)

See:

SYSDATE9 Automatic Macro Variable” on page 203

Details

SYSDATE contains a SAS date value in the DATE7. format, which displays a two-digit date, the first three letters of the month name, and a two-digit year. The date does not change during the individual job or session. For example, you could use SYSDATE in programs to check the date before you execute code that you want to run on certain dates of the month.

Example: Formatting a SYSDATE Value

Macro FDATE assigns a format that you specify to the value of SYSDATE:

%macro fdate(fmt);
   %global fdate;
   data _null_;
      call symput("fdate",left(put("&sysdate"d,&fmt)));
   run;
%mend fdate;
%fdate(worddate.)
title "Tests for &fdate";

If you execute this macro on July 28, 1998, SAS sees the statements:

DATA _NULL_;
   CALL SYMPUT("FDATE",LEFT(PUT("28JUL98"D,WORDDATE.)));
RUN;
TITLE "Tests for July 28, 1998";

For another method of formatting the current date, see the %SYSFUNC and %QSYSFUNC functions.

SYSDATE9 Automatic Macro Variable

Contains the date that a SAS job or session began executing.

Type:

Automatic macro variable (read only)

See:

SYSDATE Automatic Macro Variable” on page 202

Details

SYSDATE9 contains a SAS date value in the DATE9. format, which displays a two-digit date, the first three letters of the month name, and a four-digit year. The date does not change during the individual job or session. For example, you could use SYSDATE9 in programs to check the date before you execute code that you want to run on certain dates of the month.

Example: Formatting a SYSDATE9 Value

Macro FDATE assigns a format that you specify to the value of SYSDATE9:

%macro fdate(fmt);
b    %global fdate;
   data _null_;
      call symput("fdate",left(put("&sysdate9"d,&fmt)));
   run;
%mend fdate;
%fdate(worddate.)
title "Tests for &fdate";

If you execute this macro on July 28, 2008, SAS sees the statements:

DATA _NULL_;
   CALL SYMPUT("FDATE",LEFT(PUT("28JUL2008"D,WORDDATE.)));
RUN;
TITLE "Tests for July 28, 2008";

For another method of formatting the current date, see the %SYSFUNC and %QSYSFUNC functions.

SYSDAY Automatic Macro Variable

Contains the day of the week that a SAS job or session began executing.

Type:

Automatic macro variable (read only)

Details

You can use SYSDAY to check the current day before executing code that you want to run on certain days of the week, provided you initialized your SAS session today.

Example: Identifying the Day When a SAS Session Started

The following statement identifies the day and date when a SAS session started running.

%put This SAS session started running on: &sysday, &sysdate9.;

When this statement executes on Wednesday, December 19, 2007 for a SAS session that began executing on Monday, December 17, 2007, the following line is written to the SAS log:

This SAS session started running on: Monday, 17DEC2007

SYSDEVIC Automatic Macro Variable

Contains the name of the current graphics device.

Type:

Automatic macro variable (read and write)

Details

The current graphics device is the one specified at invocation of SAS. You can specify the graphics device on the command line in response to a prompt when you use a product that uses SAS/GRAPH. You can also specify the graphics device in a configuration file. The name of the current graphics device is also the value of the SAS system option DEVICE=.

For details, see the SAS documentation for your operating environment.

Note: The macro processor always stores the value of SYSDEVIC in unquoted form. To quote the resolved value of SYSDEVIC, use the %SUPERQ macro quoting function.

Comparisons

Assigning a value to SYSDEVIC is the same as specifying a value for the DEVICE= system option.

SYSDMG Automatic Macro Variable

Contains a return code that reflects an action taken on a damaged data set.

Type:

Automatic macro variable (read and write)

Default:

0

Details

You can use the value of SYSDMG as a condition to determine further action to take.

SYSDMG can contain the following values:

Table 14.2 SYSDMG Values and Descriptions

Value

Description

0

No repair of damaged data sets in this session. (Default)

1

One or more automatic repairs of damaged data sets have occurred.

2

One or more user-requested repairs of damaged data sets have occurred.

3

One or more opens failed because the file was damaged.

4

One or more SAS tasks were terminated because of a damaged data set.

5

One or more automatic repairs of damaged data sets have occurred; the last-repaired data set has index file removed, as requested.

6

One or more user requested repairs have occurred; the last-repaired data set has index file removed, as requested.

SYSDSN Automatic Macro Variable

Contains the libref and name of the most recently created SAS data set.

Type:

Automatic macro variable (read and write)

See:

SYSLAST Automatic Macro Variable” on page 212

Details

The libref and data set name are displayed in two left-aligned fields. If no SAS data set has been created in the current program, SYSDSN returns eight blanks followed by _NULL_ followed by two more blanks.

Note: The macro processor always stores the value of SYSDSN in unquoted form. To quote the resolved value of SYSDSN, use the %SUPERQ macro quoting function.

Comparisons

• Assigning a value to SYSDSN is the same as specifying a value for the _LAST_= system option.

• The value of SYSLAST is often more useful than SYSDSN because the value of SYSLAST is formatted so that you can insert a reference to it directly into SAS code in place of a data set name.

Example: Comparing Values Produced by SYSDSN and SYSLAST

Create a data set Work.Test and then enter the following statements:

%put Sysdsn produces:  *&sysdsn*;
%put Syslast produces: *&syslast*;

When these statements execute, the following lines are written to the SAS log:

Sysdsn produces:  *WORK  TEST  *
Syslast produces: *WORK.TEST  *

When the libref or data set name contain fewer than eight characters, SYSDSN maintains the blanks for the unused characters. SYSDSN does not display a period between the libref and data set name fields.

SYSENCODING Automatic Macro Variable

Contains the name of the SAS session encoding.

Type:

Automatic macro variable (ready only)

Details

SYSENCODING displays the name with a maximum length of 12 bytes.

Example: Using SYSENCODING to Display the SAS Session Encoding

The following statement displays the encoding for the SAS session:

%put The encoding for this SAS session is: &sysencoding;

When this statement executes, the following comment is written to the SAS log:

The encoding for this SAS session is: wlatin1

SYSENDIAN Automatic Macro Variable

Contains an indication of the byte order of the current session. The possible values are LITTLE or BIG.

Type:

Automatic macro variable (read only)

Details

The SYSENDIAN automatic macro variable indicates the byte order of the current SAS session. There are two possible values: LITTLE and BIG.

SYSENV Automatic Macro Variable

Reports whether SAS is running interactively.

Type:

Automatic macro variable (read only)

Details

The value of SYSENV is independent of the source of input. The following are values for SYSENV:

FORE

when the SAS system option TERMINAL is in effect. For example, the value is FORE when you run SAS interactively through a windowing environment.

BACK

when the SAS system option NOTERMINAL is in effect. For example, the value is BACK when you submit a SAS job in batch mode.

You can use SYSENV to check the execution mode before submitting code that requires interactive processing. To use a %INPUT statement, the value of SYSENV must be FORE. For details, see the SAS documentation for your operating environment.

Operating Environment Information

Some operating environments do not support the submission of jobs in batch mode. In this case the value of SYSENV is always FORE. For details, see the SAS documentation for your operating environment.

SYSERR Automatic Macro Variable

Contains a return code status set by some SAS procedures and the DATA step.

Type:

Automatic macro variable (read only)

Details

You can use the value of SYSERR as a condition to determine further action to take or to decide which parts of a SAS program to execute. SYSERR is used to detect major system errors, such as out of memory or failure of the component system when used in some procedures and DATA steps. SYSERR automatic macro variable is reset at each step boundary. For the return code of a complete job, see “SYSCC Automatic Macro Variable” on page 199.

SYSERR can contain the following values:

Table 14.3 SYSERR Values

Value

Description

0

Execution completed successfully and without warning messages.

1

Execution was canceled by a user with a RUN CANCEL statement.

2

Execution was canceled by a user with an ATTN or BREAK command.

3

An error in a program run in batch or non-interactive mode caused SAS to enter syntax-check mode.

4

Execution completed successfully but with warning messages.

5

Execution was canceled by a user with an ABORT CANCEL statement.

6

Execution was canceled by a user with an ABORT CANCEL FILE statement.

>6

An error occurred. The value returned is procedure-dependent.

The following table contains warning return codes. The codes do not indicate any specific problems. These codes are guidelines to identify the nature of a problem.

Table 14.4 SYSERR Warning Codes

Warning Code

Description

108

Problem with one or more BY groups

112

Error with one or more BY groups

116

Memory problems with one or more BY groups

120

I/O problems with one or more BY groups

The following table contains error return codes. The codes do not indicate any specific problems. These codes are guidelines to identify the nature of a problem.

Table 14.5 SYSERR Error Codes

Error Code

Description

1008

General data problem

1012

General error condition

1016

Out-of-memory condition

1020

I/O problem

2000

Semantic action problem

2001

Attribute processing problem

3000

Syntax error

4000

Not a valid procedure

9999

Bug in the procedure

20000

A step was stopped or an ABORT statement was issued.

20001

An ABORT RETURN statement was issued.

20002

An ABORT ABEND statement was issued.

25000

Severe system error. The system cannot initialize or continue.

Example: Using SYSERR

The example creates an error message and uses %PUT &SYSERR to write the return code number (1012) to the SAS log.

data NULL;
   set doesnotexist;
run;
%put &syserr;

The following SAS log output contains the return code number:

2
3      data NULL;
4       set doesnotexist;
ERROR: File WORK.DOESNOTEXIST.DATA does not exist.
5    run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NULL may be incomplete.  When this step was stopped
there were 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           1:03.70
      cpu time            0.07 seconds


6    %put &=syserr;
SYSERR=1012

To retrieve error and warning text instead of the return code number, see “SYSERRORTEXT Automatic Macro Variable” on page 209 and “SYSWARNINGTEXT Automatic Macro Variable” on page 230.

SYSERRORTEXT Automatic Macro Variable

Contains the text of the last error message formatted for display in the SAS log.

Type:

Automatic macro variable (read only)

Details

The value of SYSERRORTEXT is the text of the last error message generated in the SAS log. For a list of SYSERR warnings and errors, see “SYSERR Automatic Macro Variable” on page 207.

Note: If the last error message text that was generated contains an & or % and you are using the %PUT statement, you must use the %SUPERQ macro quoting function to mask the special characters to prevent further resolution of the value. The following example uses the %PUT statement and the %SUPERQ macro quoting function:

%put %superq(syserrortext);

For more information, see “%SUPERQ Function” on page 269.

Example: Using SYSERRORTEXT

This example creates an error message:

data NULL;
   set doesnotexist;
run;
%put &syserrortext;

When these statements are executed, the following record is written to the SAS log:

1   data NULL;
2   set doesnotexist;
ERROR: File WORK.DOESNOTEXIST.DATA does not exist.
3   run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NULL might be incomplete. When this step was
         stopped there were 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time       11.16 seconds
cpu time        0.07 seconds
4  %put &syserrortext;
File WORK.DOESNOTEXIST.DATA does not exist.

SYSFILRC Automatic Macro Variable

Contains the return code from the last FILENAME statement.

Type:

Automatic macro variable (read and write)

Details

SYSFILRC checks whether the file or storage location referenced by the last FILENAME statement exists. You can use SYSFILRC to confirm that a file or location is allocated before attempting to access an external file.

The following are values for SYSFILRC:

Table 14.6 SYSFILRC Values and Descriptions

Value

Description

0

The last FILENAME statement executed correctly.

≠0

The last FILENAME statement did not execute correctly.

SYSHOSTINFOLONG Automatic Macro Variable

Contains the operating environment information that is displayed when the HOSTINFOLONG option is specified.

Type:

Automatic macro variable (read-only)

Details

Contains the operating environment information that is displayed when the HOSTINFOLONG option is specified. For more information, see HOSTINFOLONG system option in SAS System Options: Reference.

SYSHOSTNAME Automatic Macro Variable

Contains the host name of a computer.

Type:

Automatic macro variable (read only)

Details

SYSHOSTNAME contains the host name of the system that is running a single TCPIP stack. For more information about TCPIP stacks, see your SAS host companion documentation.

SYSINDEX Automatic Macro Variable

Contains the number of macros that have started execution in the current SAS job or session.

Type:

Automatic macro variable (read only)

Details

You can use SYSINDEX in a program that uses macros when you need a unique number that changes after each macro invocation.

SYSINFO Automatic Macro Variable

Contains return codes provided by some SAS procedures.

Type:

Automatic macro variable (read only)

Details

Values of SYSINFO are described with the procedures that use it. You can use the value of SYSINFO as a condition for determining further action to take or parts of a SAS program to execute.

For example, PROC COMPARE, which compares two data sets, uses SYSINFO to store a value that provides information about the result of the comparison.

SYSJOBID Automatic Macro Variable

Contains the name of the current batch job or user ID.

Type:

Automatic macro variable (read only)

Details

The value stored in SYSJOBID depends on the operating environment that you use to run SAS. You can use SYSJOBID to check who is currently executing the job to restrict certain processing or to issue commands that are specific to a user.

SYSLAST Automatic Macro Variable

Contains the name of the SAS data file created most recently.

Type:

Automatic macro variable (read and write)

See:

SYSDSN Automatic Macro Variable” on page 205

Details

The name is stored in the form libref.dataset. You can insert a reference to SYSLAST directly into SAS code in place of a data set name. If no SAS data set has been created in the current program, the value of SYSLAST is _NULL_, with no leading or trailing blanks.

Note: The macro processor always stores the value of SYSLAST in unquoted form. To quote the resolved value of SYSLAST, use the %SUPERQ macro quoting function.

Comparisons

• Assigning a value to SYSLAST is the same as specifying a value for the _LAST_= system option.

• The value of SYSLAST is often more useful than SYSDSN because the value of SYSLAST is formatted so that you can insert a reference to it directly into SAS code in place of a data set name.

Example: Comparing Values Produced by SYSLAST and SYSDSN

Create the data set FirstLib.SalesRpt and then enter the following statements:

%put Sysdsn produces:  *&sysdsn*;
%put Syslast produces: *&syslast*;

When these statements are executed, the following is written to the SAS log:

Sysdsn produces:  *FIRSTLIBSALESRPT*
Syslast produces: *FIRSTLIB.SALESRPT*

The name stored in SYSLAST contains the period between the libref and data set name.

SYSLCKRC Automatic Macro Variable

Contains the return code from the most recent LOCK statement.

Type:

Automatic macro variable (read and write)

Details

The LOCK statement is a Base SAS software statement used to acquire and release an exclusive lock on data objects in data libraries accessed through SAS/SHARE software. The following are values for SYSLCKRC:

Table 14.7 LCKRC Values and Descriptions

Value

Description

0

The last LOCK statement was successful.

>0

The last LOCK statement was not successful.

<0

The last LOCK statement was completed, but a WARNING or NOTE was written to the SAS log.

For more information, see the documentation for SAS/SHARE software.

SYSLIBRC Automatic Macro Variable

Contains the return code from the last LIBNAME statement.

Type:

Automatic macro variable (read and write)

Details

The code reports whether the last LIBNAME statement executed correctly. SYSLIBRC checks whether the SAS library referenced by the last LIBNAME statement exists. For example, you could use SYSLIBRC to confirm that a libref is allocated before you attempt to access a permanent data set.

The following are values for SYSLIBRC:

Table 14.8 SYSLIBRC Values and Descriptions

Value

Description

0

The last LIBNAME statement executed correctly.

≠0

The last LIBNAME statement did not execute correctly.

SYSLOGAPPLNAME Automatic Macro Variable

Contains the value of the LOGAPPLNAME= system option.

Type:

Automatic macro variable (read only)

Default:

null

Details

The following code, when submitted from the current SAS session, writes the LOGAPPLNAME for the current SAS session to the log:

%put &syslogapplname;

SYSMACRONAME Automatic Macro Variable

Returns the name of the currently executing macro.

Type:

Automatic macro variable (read only)

Details

When referenced outside of an executing macro, SYSMACRONAME returns the null string.

SYSMENV Automatic Macro Variable

Contains the invocation status of the macro that is currently executing.

Type:

Automatic macro variable (read only)

Details

The following are values for SYSMENV:

Table 14.9 SMENV Values and Descriptions

Value

Description

S

The macro currently executing was invoked as part of a SAS program.

D

The macro currently executing was invoked from the command line of a SAS window.

SYSMSG Automatic Macro Variable

Contains text to display in the message area of a macro window.

Type:

Automatic macro variable (read and write)

Details

Values assigned to SYSMSG do not require quotation marks. The value of SYSMSG is set to null after each execution of a %DISPLAY statement.

Example: %DISPLAY Statement

This example shows that text assigned to SYSMSG is cleared after the %DISPLAY statement.

%let sysmsg=Press ENTER to continue.;
%window start
   #5  @28 'Welcome to SAS';
%display start;
%put Sysmsg is: *&sysmsg*;

When this program executes, the following is written to the SAS log:

Sysmsg is: **

SYSNCPU Automatic Macro Variable

Contains the current number of processors available to SAS for computations.

Type:

Automatic Macro Variable (Read Only)

Details

SYSNCPU is an automatic macro variable that provides the current value of the CPUCOUNT option. For more information, see “CPUCOUNT= System Option” in SAS System Options: Reference.

Comparisons

The following example shows the option CPUCOUNT set to 265.

options cpucount=265;
%put &sysncpu;

The output of the above example is 265.

SYSNOBS Automatic Macro Variable

Contains the number of observations in the last data set created by a procedure or DATA step.

Type:

Automatic macro variable (read only)

Details

The SYSNOBS contains the number of observations in the last data set created by a procedure or DATA step.

Note: If the number of observations for the data set was not calculated by the previous procedure or DATA step, the value of SYSNOBS is set to -1.

SYSODSESCAPECHAR Automatic Macro Variable

Displays the value of the ODS ESCAPECHAR= from within the program.

Type:

Automatic macro variable (read only)

Details

SYSODSESCAPECHAR automatic macro variable contains the current ODS escape character.

SYSODSPATH Automatic Macro Variable

Contains the current Output Delivery System (ODS) pathname.

Type:

Automatic macro variable (read only)

Restriction:

The SYSODSPATH automatic macro variable exists only when an ODS or PROC TEMPLATE statement is invoked.

Details

The SYSODSPATH automatic macro variable contains the current ODS pathname.

SYSPARM Automatic Macro Variable

Contains a character string that can be passed from the operating environment to SAS program steps.

Type:

Automatic macro variable (read and write)

Details

SYSPARM enables you to pass a character string from the operating environment to SAS program steps and provides a means of accessing or using the string while a program is executing. For example, you can use SYSPARM from the operating environment to pass a title statement or a value for a program to process. You can also set the value of SYSPARM within a SAS program. SYSPARM can be used anywhere in a SAS program. The default value of SYSPARM is null (zero characters).

SYSPARM is most useful when specified at invocation of SAS. For details, see the SAS documentation for your operating environment.

Note: The macro processor always stores the value of SYSPARM in unquoted form. To quote the resolved value of SYSPARM, use the %SUPERQ macro quoting function.

Comparisons

• Assigning a value to SYSPARM is the same as specifying a value for the SYSPARM= system option.

• Retrieving the value of SYSPARM is the same as using the SYSPARM() SAS function.

Example: Passing a Value to a Procedure

In this example, you invoke SAS on a UNIX operating environment on September 20, 2011 (the librefs Dept and Test are defined in the config.sas file) with a command like the following:

sas program-name -sysparm dept.projects -config /myid/config.sas

Macro variable SYSPARM supplies the name of the data set for PROC REPORT:

proc report data=&sysparm
     report=test.resorces.priority.rept;
title "%sysfunc(date(),worddate.)";
title2;
title3 'Active Projects By Priority';
run;

SAS sees the following:

proc report data=dept.projects
     report=test.resorces.priority.rept;
title "September 20, 2011";
title2;
title3 'Active Projects By Priority';
run;

SYSPBUFF Automatic Macro Variable

Contains text supplied as macro parameter values.

Type:

Automatic macro variable (read and write, local scope)

Details

SYSPBUFF resolves to the text supplied as parameter values in the invocation of a macro that is defined with the PARMBUFF option. For name-style invocations, this text includes the parentheses and commas. Using the PARMBUFF option and SYSPBUFF, you can define a macro that accepts a varying number of parameters at each invocation.

If the macro definition includes both a set of parameters and the PARMBUFF option, the macro invocation causes the parameters to receive values and the entire invocation list of values to be assigned to SYSPBUFF.

Example: Using SYSPBUFF to Display Macro Parameter Values

The macro PRINTZ uses the PARMBUFF option to define a varying number of parameters and SYSPBUFF to display the parameters specified at invocation.

%macro printz/parmbuff;
   %put Syspbuff contains: &syspbuff;
   %let num=1;
   %let dsname=%scan(&syspbuff,&num);
   %do %while(&dsname ne);
      proc print data=&dsname;
      run;
      %let num=%eval(&num+1);
      %let dsname=%scan(&syspbuff,&num);
   %end;
%mend printz;
%printz(purple,red,blue,teal)

When this program executes, this line is written to the SAS log:

Syspbuff contains: (purple,red,blue,teal)

SYSPROCESSID Automatic Macro Variable

Contains the process ID of the current SAS process.

Type:

Automatic macro variable (read only)

Default:

null

Details

The process ID is a 32–character hexadecimal string. The default value is null.

Example: Using SYSPROCESSID to Display the Current SAS Process ID

The following code writes the current SAS process ID to the SAS log:

%put &sysprocessid;

A process ID, such as the following, is written to the SAS log:

41D1B269F86C7C5F4010000000000000

SYSPROCESSMODE Automatic Macro Variable

Contains the name of the current SAS session run mode or server type.

Type:

Automatic macro variable (read-only)

Details

SYSPROCESSMODE is a read-only automatic macro variable, which contains the name of the current SAS session run mode or server type, such as the following:

• SAS DMS Session

• SAS Batch Mode

• SAS Line Mode

• SAS/CONNECT Session

• SAS Share Server

• SAS IntrNet Server

• SAS Workspace Server

• SAS Pooled Workspace Server

• SAS Stored Process Server

• SAS OLAP Server

• SAS Table Server

• SAS Metadata Server

Example: Using SYSPROCESSMODE to Display the Current SAS Process Run Mode or Server Type

%put &sysprocessmode;

A run mode or server type, such as the following is written to the log:

SAS IntrNet Server

SYSPROCESSNAME Automatic Macro Variable

Contains the process name of the current SAS process.

Type:

Automatic macro variable (read only)

Example: Using SYSPROCESSNAME to Display the Current SAS Process Name

The following statement writes the name of the current SAS process to the log:

%put &sysprocessname;

If you submit this statement in the SAS windowing environment of your second SAS session, the following line is written to the SAS log:

DMS Process (2)

SYSPROCNAME Automatic Macro Variable

Contains the name of the procedure (or DATASTEP for DATA steps) currently being processed by the SAS Language Processor.

Type:

Automatic macro variable (read only)

Details

The value of SYSPROCNAME contains the name of the procedure specified by the user in the PROC statement until a step boundary is reached.

SYSRC Automatic Macro Variable

Contains the last return code generated by your operating system.

Type:

Automatic macro variable (read and write)

Details

The code returned by SYSRC is based on commands that you execute using the X statement in open code, the X command in a windowing environment, or the %SYSEXEC, %TSO, or %CMS macro statements. Return codes are integers. The default value of SYSRC is 0.

You can use SYSRC to check the return code of a system command before you continue with a job. For return code examples, see the SAS companion for your operating environment.

SYSSCP and SYSSCPL Automatic Macro Variables

Contain an identifier for your operating environment.

Type:

Automatic macro variable (read only)

Details

SYSSCP and SYSSCPL resolve to an abbreviation of the name of your operating environment. In some cases, SYSSCPL provides a more specific value than SYSSCP. You could use SYSSCP and SYSSCPL to check the operating environment to execute appropriate system commands.

The following table lists the values for SYSSCP and SYSSCPL.

Table 14.10 SYSSCP and SYSSCPL Values for Platforms Running SAS 9.2 or Later

Platform

SYSSCP Value

SYSSCPL Value

z/OS

OS

z/OS

VMI or OpenVMS on Itanium - supported for Foundation SAS only

VMS ITAN

OpenVMS

UNIX

HP-UX PA-RISC or H64

HP 64

HP-UX

H61 or HP-UX IPF or HPUX on Itanium

HP IPF

HP-UX

LAX or LINUX on X64 (x86-64)

LIN X64

LINUX or Linux

LNX or LINUX or LINUX 32-bit (x86)

LINUX

LINUX or Linux

R64 or AIX64 or AIX on POWER

AIX 64

AIX

S64 or SUN64 or Solaris on SPARC

SUN 64

SUNOS or SunOS

SAX or Solaris 10 on X64 (x86-64)

SUN X64

SUNOS or SunOS

Windows

Windows XP Pro

WIN

XP_PRO

Windows Server 2003

WIN

NET_SRV

Windows Enterprise Server 2003

WIN

NET_ASRV

Windows Data Center Server 2003

WIN

NET_DSRV

Windows XP Pro x64

WIN

X64_PRO

Windows Server 2003 x64

WIN

X64_SRV

Windows Enterprise Server 2003 x64

WIN

X64_ESRV

Windows Data Center Server 2003 x64

WIN

X64_DSRV

Windows Vista Business

WIN

W32_VSPRO

Windows Server 2008

WIN

W32_SRV08

Windows Enterprise Server 2008

WIN

W32_ESRV08

Windows Data Center Server 2008

WIN

W32_DSRV08

Windows Vista Business x64

WIN

X64_VSPRO

Windows Server 2008 x64

WIN

X64_SRV08

Windows Enterprise Server 2008 x64

WIN

X64_ESRV08

Windows Data Center Server 2008 x64

WIN

X64_DSRV08

Windows Server 2008 R2 x64

WIN

X64_S08R2

Windows Enterprise Server 2008 R2 X64

WIN

X64_ES08R2

Windows Data Center Server 2008 R2 x64

WIN

X64_DS08R2

Windows Server 2008 Itanium

WIN

W64_ESRV08

Windows Itanium Enterprise Server 2003 or W64_ASRV

WIN

W64_ASRV

Windows Itanium Data Center Server 2003 or W64_DSRV

WIN

W64_DSRV

Windows Itanium Server 2003

WIN

W64_SRV

Example: Deleting a Temporary File on a Platform Running SAS

The macro DELFILE locates the platform that is running SAS and deletes the TMP file. FILEREF is a global macro variable that contains the fileref for the TMP file.

%macro delfile;
   %if  /* HP Unix */&sysscp=HP 64 or &sysscp=AIX 64
   %then

   %do;
      X "rm &fileref..TMP";
   %end;
   %else %if  /* DOS-LIKE PLATFORM */&sysscp=WIN
%then
   %do;
      X "DEL &fileref..TMP";
   %end;
%mend delfile;

SYSSCPL Automatic Macro Variable

Contains the name of your operating environment.

Type:

Automatic macro variable (read only)

Details

See “SYSSCP and SYSSCPL Automatic Macro Variables” on page 220

SYSSITE Automatic Macro Variable

Contains the number assigned to your site.

Type:

Automatic macro variable (read only)

Details

SAS assigns a site number to each site that licenses SAS software. The number is displayed in the SAS log.

SYSSIZEOFLONG Automatic Macro Variable

Contains the length in bytes of a long integer in the current session.

Type:

Automatic macro variable (read only)

Details

The SYSSIZEOFLONG automatic macro variable contains the length of a long integer in the current SAS session.

SYSSIZEOFPTR Automatic Macro Variable

Contains the size in bytes of a pointer.

Type:

Automatic macro variable (read only)

Details

The SYSSIZEOFPTR automatic macro variable contains the size in bytes of a pointer.

SYSSIZEOFUNICODE Automatic Macro Variable

Contains the length in bytes of a Unicode character in the current session.

Type:

Automatic macro variable (read only)

Details

The SYSSIZEOFUNICODE automatic macro variable contains the length of the Unicode character in the current SAS session.

SYSSTARTID Automatic Macro Variable

Contains the ID generated from the last STARTSAS statement (experimental).

Type:

Automatic macro variable (read only)

Default:

null

Note:

STARTSAS statement is an experimental feature of the SAS System.

Details

The ID is a 32-character hexadecimal string that can be passed to the WAITSAS statement or the ENDSAS statement. The default value is null.

Example: Using SYSSTARTID to Display the SAS Process ID from the Most Recent STARTSAS Statement (experimental)

Submit the following code from the SAS process in which you have submitted the most recent STARTSAS statement to write the value of the SYSSTARTID variable to the SAS log:

%put &sysstartid

A process ID value, such as the following, is written to the SAS log:

41D20425B89FCED94036000000000000

SYSSTARTNAME Automatic Macro Variable

Contains the process name generated from the last STARTSAS statement (experimental).

Type:

Automatic macro variable (read only)

Default:

null

Note:

STARTSAS statement is an experimental feature of the SAS System.

Example: Using SYSSTARTNAME to Display the SAS Process Name from the Most Recent STARTSAS Statement (experimental)

Submit the following code from the SAS process in which you have submitted the most recent STARTSAS statement to write the value of the SYSSTARTNAME variable to the SAS log:

%put &sysstartname;

An example of a process name that can appear in the SAS log is as follows:

DMS Process (2)

SYSTCPIPHOSTNAME Automatic Macro Variable

Contains the host names of the local and remote computers when multiple TCP/IP stacks are supported.

Type:

Automatic macro variable (read only)

Details

SYSTCPIPHOSTNAME contains the host name of the system that is running multiple TCPIP stacks. For more information about TCPIP stacks, see your SAS host companion documentation.

SYSTIME Automatic Macro Variable

Contains the time a SAS job or session began executing.

Type:

Automatic macro variable (read only)

Details

The value is displayed in TIME5. format and does not change during the individual job or session.

Example: Using SYSTIME to Display the Time That a SAS Session Started

The following statement displays the time a SAS session started.

%put This SAS session started running at: &systime;

When this statement executes at 3 p.m., but your SAS session began executing at 9:30 a.m., the following comment is written to the SAS log:

This SAS session started running at: 09:30

SYSTIMEZONE Automatic Macro Variable

Contains the time zone name based on TIMEZONE option.

Type:

Automatic macro variable (read only)

Details

SYSTIMEZONE contains the time zone name based on the current value of the TIMEZONE option. For more information about the TIMEZONE option, see the SAS documentation for your operating environment.

Example Code 14.1 Using SYSTIMEZONE

option timezone='america/new_york';
%put &=systimezone;

option timezone='america/chicago';
%put &=systimezone;

option timezone='america/denver';
%put &=systimezone;

option timezone='america/los_angeles';
%put &=systimezone;

Log 14.1 Output

114   option timezone='america/new_york';
115   %put &=systimezone;
SYSTIMEZONE=EDT
116   option timezone='america/chicago';
117   %put &=systimezone;
SYSTIMEZONE=CDT
118   option timezone='america/denver';
119   %put &=systimezone;
SYSTIMEZONE=MDT
120   option timezone='america/los_angeles';
121   %put &=systimezone;
SYSTIMEZONE=PDT

SYSTIMEZONEIDENT Automatic Macro Variable

Contains the time zone ID based on the TIMEZONE= system option.

Type:

Automatic macro variable (read only)

Details

SYSTIMEZONEIDENT contains the time zone ID based on the current value of the TIMEZONE= system option. For more information about the TIMEZONE= option, see the SAS documentation for your operating environment.

Example Code 14.2 Using SYSTIMEZONEIDENT

option timezone='america/new_york';
%put &=systimezoneident;

option timezone='america/chicago';
%put &=systimezoneident;

 option timezone='america/denver';
%put &=systimezoneident;

option timezone='america/los_angeles';
%put &=systimezoneident;

Log 14.2 Output

12   option timezone='america/new_york';
13   %put &=systimezoneident;
SYSTIMEZONEIDENT=AMERICA/NEW_YORK
14
15   option timezone='america/chicago';
16   %put &=systimezoneident;
SYSTIMEZONEIDENT=AMERICA/CHICAGO
17
18   option timezone='america/denver';
19   %put &=systimezoneident;
SYSTIMEZONEIDENT=AMERICA/DENVER
20
21   option timezone='america/los_angeles';
22   %put &=systimezoneident;
SYSTIMEZONEIDENT=AMERICA/LOS_ANGELES

SYSTIMEZONEOFFSET Automatic Macro Variable

Contains the current time zone offset based on TIMEZONE option.

Type:

Automatic Macro Variable

Details

SYSTIMEZONEOFFSET contains the time zone offset based on the current value of the TIMEZONE option. For more information about the TIMEZONE option, see the SAS documentation for your operating environment.

Example Code 14.3 Using SYSTIMEZONEOFFSET

option timezone='america/new_york';
%put &=systimezoneoffset;

option timezone='america/chicago';
%put &=systimezoneoffset;

option timezone='america/denver';
%put &=systimezoneoffset;

option timezone='america/los_angeles';
%put &=systimezoneoffset;

Log 14.3 Output

153   option timezone='america/new_york';
154   %put &=systimezoneoffset;
SYSTIMEZONEOFFSET=-14400
155   option timezone='america/chicago';
156   %put &=systimezoneoffset;
SYSTIMEZONEOFFSET=-18000
157   option timezone='america/denver';
158   %put &=systimezoneoffset;
SYSTIMEZONEOFFSET=-21600
159   option timezone='america/los_angeles';
160   %put &=systimezoneoffset;
SYSTIMEZONEOFFSET=-25200

SYSUSERID Automatic Macro Variable

Contains the user ID or login of the current SAS process.

Type:

Automatic macro variable (read only)

Example: Using SYSUSERID to Display the User ID for the Current SAS Process

The following code, when submitted from the current SAS process, writes the user ID or login for the current SAS process to the SAS log:

%put &sysuserid;

A user ID, such as the following, is written to the SAS log:

MyUserid

SYSVER Automatic Macro Variable

Contains the release number of SAS software that is running.

Type:

Automatic macro variable (read only)

See:

SYSVLONG Automatic Macro Variable” on page 229 and “SYSVLONG4 Automatic Macro Variable” on page 229

Comparisons

SYSVER provides the release number of the SAS software that is running. You can use SYSVER to check for the release of SAS before running a job with newer features.

Example: Identifying SAS Software Release

The following statement displays the release number of a user’s SAS software.

%put I am using release: &sysver;

Submitting this statement (for a user of SAS 9.2) writes the following to the SAS log:

I am using release: 9.2

SYSVLONG Automatic Macro Variable

Contains the release number and maintenance level of SAS software that is running.

Type:

Automatic macro variable (read only)

See:

SYSVER Automatic Macro Variable” on page 228 and “SYSVLONG4 Automatic Macro Variable” on page 229

Comparisons

SYSVLONG provides the release number and maintenance level of SAS software, in addition to the release number.

Example: Identifying a SAS Maintenance Release

The following statement displays information identifying the SAS release being used.

%put I am using release: &sysvlong;

Submitting this statement (for a user of SAS 9.2) writes the following to the SAS log:

I am using release: 9.02.02M2D071609

SYSVLONG4 Automatic Macro Variable

Contains the release number and maintenance level of SAS software that is running and has a four-digit year.

Type:

Automatic macro variable (read only)

See:

SYSVER Automatic Macro Variable” on page 228 and “SYSVLONG Automatic Macro Variable” on page 229

Comparisons

SYSVLONG4 provides a four-digit year and the release number and maintenance level of SAS software. SYSVLONG does not contain the four-digit year but everything else is the same.

Example: Using SYSVLONG4 Automatic Macro Variable

The following statement displays information that identifies the SAS release being used.

%put I am using maintenance release: &sysvlong4;

Submitting this statement (for a user of SAS 9.2) writes this comment to the SAS log:

I am using maintenance release: 9.02.01B0D09112007

SYSWARNINGTEXT Automatic Macro Variable

Contains the text of the last warning message formatted for display in the SAS log.

Type:

Automatic macro variable (read only)

Details

The value of SYSWARNINGTEXT is the text of the last warning message generated in the SAS log. For a list of SYSERR warnings and errors, see “SYSERR Automatic Macro Variable” on page 207.

Note: If the last warning message text that was generated contains an & or % and you are using the %PUT statement, you must use the %SUPERQ macro quoting function to mask the special characters to prevent further resolution of the value. The following example uses the %PUT statement and the %SUPERQ macro quoting function:

%put %superq(syswarningtext);

For more information, see “%SUPERQ Function” on page 269.

Example: Using SYSWARNINGTEXT

This example creates a warning message:

data NULL;
    set doesnotexist;
run;
%put &syswarningtext;

When these statements execute, the following comments are written to the SAS log:

1  data NULL;
 2  set doesnotexist;
 ERROR: File WORK.DOESNOTEXIST.DATA does not exist.
 3  run;
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.NULL might be incomplete.  When this step
          was stopped there were 0 observations and 0 variables.
 NOTE: DATA statement used (Total process time):
     real time               11.16 seconds
     cpu time                0.07 seconds
 4  %put &syswarningtext;
The data set WORK.NULL might be incomplete.  When this step was
stopped there were 0 observations and 0 variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.232.152