MACROS AND MACRO VARIABLES:
SAS Macro program consists two basic building blocks (Macro triggers):
1) Macros
2) Macro variables.
Macros start with a percent sign (%) and
Macro variables start with an ampersand (&)
Macro variables are 2 types
i) System defined (Automatic macro variables)
ii) User defined Macro variables
User defined macro variables are again 2 types i) Global ii) Local
SCOPE OF THE MACRO VARIABLES
Macro variables can have two kind of scope
1) Global
2) Local
A macro variable is Local if it is defined inside a macro
A macro variable is Global if it is defined open code or outside a macro
We can use a Local macro variable only inside its own macro
But we can use Global macro variable anywhere in sas program
YOU MAY QUOTE ME ON THAT
Another caveat to keep in mind is that the macro processor doesn’t check for macros inside single quotes. To get around this, simply use double quotes for titles or other quoted strings that contain macro code.
Automatic variables are
Read/Write
SYSBUFFER unmatched text from %INPUT
SYSCC the current condition code that SAS returns to your operating environment (the operating environment condition code)
SYSCMD last unrecognized command from the command line of a macro window
SYSDEVIC name of current graphics device
SYSDMG return code that reflects an action taken on a damaged data set
SYSDSN name of most recent SAS data set in two fields
SYSFILRC return code set by the FILENAME statement
SYSLAST name of most recent SAS data set in one field
SYSLCKRC return code set by the LOCK statement
SYSLIBRC return code set by the LIBNAME statement
SYSMSG message for display in macro window
SYSPARM value specified with the SYSPARM= system option
SYSPBUFF text of macro parameter values
SYSRC various system-related return codes
Read-Only
SYSCHARWIDTH the character width value
SYSDATE the character value representing the date a SAS job or session began executing (two-digit year)
SYSDATE9 the character value representing the date a SAS job or session began executing (four-digit year)
SYSDAY day of week SAS job or session began executing
SYSENV foreground or background indicator
SYSERR return code set by SAS procedures and the DATA step
SYSINDEX number of macros that have begun execution during this session
SYSINFO return code information
SYSJOBID name of current batch job or user id (varies by host environment)
SYSMENV current macro execution environment
SYSPROCESSID the process id of the current SAS process
SYSPROCESSNAME the process name of the current SAS process
SYSSCP the abbreviation of an operating system
SYSSCPL the name of an operating system
SYSSITE the number assigned to your site
SYSSTARTID the id generated from the last STARTSAS statement
SYSSTARTNAME the process name generated from the last STARTSAS statement
SYSTIME the character value of the time a SAS job or session began executing
SYSUSERID the userid or login of the current SAS process
SYSVER release or version number of SAS software executing
SYSVLONG release number and maintenance level of SAS software
Automatic variables are global except SYSPBUFF, which is local.
USE %PUT _AUTOMATIC_ to see all the automatic variables in sas log.
%put _automatic_;
Run above program to see all the automatic macro variable information in sas log
And look on the values for automatic macro variables.
AUTOMATIC AFDSID 0
AUTOMATIC AFDSNAME
AUTOMATIC AFLIB
AUTOMATIC AFSTR1
AUTOMATIC AFSTR2
AUTOMATIC FSPBDV
AUTOMATIC SYSBUFFR
AUTOMATIC SYSCC 0
AUTOMATIC SYSCHARWIDTH 1
AUTOMATIC SYSCMD
AUTOMATIC SYSDATE 27NOV10
AUTOMATIC SYSDATE9 27NOV2010
AUTOMATIC SYSDAY Saturday
AUTOMATIC SYSDEVIC
AUTOMATIC SYSDMG 0
AUTOMATIC SYSDSN _NULL_
AUTOMATIC SYSENCODING wlatin1
AUTOMATIC SYSENDIAN LITTLE
AUTOMATIC SYSENV FORE
AUTOMATIC SYSERR 0
AUTOMATIC SYSERRORTEXT
AUTOMATIC SYSFILRC 0
AUTOMATIC SYSHOSTNAME computer
AUTOMATIC SYSINDEX 0
AUTOMATIC SYSINFO 0
AUTOMATIC SYSJOBID 4144
AUTOMATIC SYSLAST _NULL_
AUTOMATIC SYSLCKRC 0
AUTOMATIC SYSLIBRC 0
AUTOMATIC SYSLOGAPPLNAME
AUTOMATIC SYSMACRONAME
AUTOMATIC SYSMAXLONG 2147483647
AUTOMATIC SYSMENV S
AUTOMATIC SYSMSG
AUTOMATIC SYSNCPU 2
AUTOMATIC SYSODSPATH SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ)
AUTOMATIC SYSPARM
AUTOMATIC SYSPBUFF
AUTOMATIC SYSPROCESSID 41D7F0343995F3B64018000000000000
AUTOMATIC SYSPROCESSNAME DMS Process
AUTOMATIC SYSPROCNAME
AUTOMATIC SYSRC 0
AUTOMATIC SYSSCP WIN
AUTOMATIC SYSSCPL XP_PRO
AUTOMATIC SYSSITE 0011600745
AUTOMATIC SYSSIZEOFLONG 4
AUTOMATIC SYSSIZEOFUNICODE 2
AUTOMATIC SYSSTARTID
AUTOMATIC SYSSTARTNAME
AUTOMATIC SYSTCPIPHOSTNAME computer
AUTOMATIC SYSTIME 10:11
AUTOMATIC SYSUSERID sasadm
AUTOMATIC SYSVER 9.2
AUTOMATIC SYSVLONG 9.02.02M2P090109
AUTOMATIC SYSVLONG4 9.02.02M2P09012009
AUTOMATIC SYSWARNINGTEXT