Automatic macro variables

From sasCommunity
Jump to: navigation, search

Automatic macro variables are macro variables that automatically exist in the SAS environment and are assigned values by the SAS system. They provide information about the state of the SAS system's environment and operating states. The information contained in can be used by SAS programs.

Although most of these macro variables are READONLY, some can be modified by the user.

Listing available variables

To see a list of automatic macro variables currently available within your SAS system you can use a %PUT statement.

 %put _automatic_ ;

Variable names

Most automatic macro variables start with SYS (&SYSDATE9), however some procedures, such as PROC SQL, and some products, such as SAS/AF, will also create automatic macro variables and these may start with other letters.

  • SYSADDRBITS
  • SYSBUFFR
  • SYSCC
  • SYSCHARWIDTH
  • SYSCMD
  • SYSDATASTEPPHASE
  • SYSDATE
  • SYSDATE9
  • SYSDAY
  • SYSDEVIC
  • SYSDMG
  • SYSDSN
  • SYSENCODING
  • SYSENDIAN
  • SYSENV
  • SYSERR
  • SYSERRORTEXT
  • SYSFILRC
  • SYSHOSTINFOLONG
  • SYSHOSTNAME
  • SYSINDEX
  • SYSINFO
  • SYSJOBID
  • SYSLAST
  • SYSLCKRC
  • SYSLIBRC
  • SYSLOGAPPLNAME
  • SYSMACRONAME
  • SYSMENV
  • SYSMSG
  • SYSNCPU
  • SYSNOBS
  • SYSODSESCAPECHAR
  • SYSODSPATH
  • SYSPARM
  • SYSPBUFF
  • SYSPRINTTOLIST
  • SYSPRINTTOLOG
  • SYSPROCESSID
  • SYSPROCESSMODE
  • SYSPROCESSNAME
  • SYSPROCNAME
  • SYSRC
  • SYSSCP
  • SYSSCPL
  • SYSSITE
  • SYSSIZEOFLONG
  • SYSSIZEOFPTR
  • SYSSIZEOFUNICODE
  • SYSSTARTID
  • SYSSTARTNAME
  • SYSTCPIPHOSTNAME
  • SYSTIME
  • SYSTIMEZONE
  • SYSTIMEZONEIDENT
  • SYSTIMEZONEOFFSET
  • SYSUSERID
  • SYSVER
  • SYSVLONG
  • SYSVLONG4
  • SYSWARNINGTEXT
  • SYS_SQLSETLIMIT
  • SQLEXITCODE
  • SQLOBS
  • SQLOOPS
  • SQLXOPENERRS
  • SQLRC
  • SQLXMSG
  • SQLXRC

Automatic variables in the DATA Step

During the DATA Step it is often difficult and inconvenient to access the current value of a macro variable or update the value. This is because macro variables are parsed when the code for the DATA Step is compiled but are only updated when the DATA Step runs. Consequently, the obvious methods of reading and assigning values to macro variables do not work as one would logically expect from an initial reading of the code. To overcome these issues there are several automatic variables that can be used within the DATA Step. These are DATA Step variables, rather than macro variables.

  • _N_
  • _ERROR_
  • BY Groups
    • FIRST.variable
    • LAST.variable
  • MODIFY statement
    • _IORC_
  • WINDOW statement
    • _CMD_
    • _MSG_

Further reading

SAS Documentation