Search notes:

SAS: automatic macro variables

Automatic variables start with either &af or &sys.
&sysdevic
&sysencoding
&sysjobid contains the unix process id
&syslibrc
&sysmacroname
&sysrc
&sysscp and &sysscpl
&syserr &syserrortext and &syswarningtext
&sqlobs

Date and time related automatic macro variables

%put sysdate:  &sysdate;   /* 18SEP17   */
%put sysdate9: &sysdate9;  /* 18SEP2017 */
%put sysday:   &sysday;    /* Monday    */
%put systime:  &systime;   /* 06:39     */
Github repository about-SAS, path: /macro-processor/variables/automatic/date-time.sas
Note: these variables record the time when the session was started. They then don't change anymore. The actual current time must be deteremined with time()
%put Time when session started: &systime;
%put Actual time %sysfunc(putn(%sysfunc(time()),time.));
Github repository about-SAS, path: /macro-processor/variables/automatic/time-sessionstart-current.sas

Last dataset created

The name of the last data set is stored in &syslast:
data;
   txt = 'demonstration of syslast';
run;

%put last dataset created is &syslast;

proc sql;
  select * from &syslast;
quit;
Github repository about-SAS, path: /macro-processor/variables/automatic/syslast.sas

Related to the host

%put _sashostname:     &_sashostname;
%put _sasservername:   &_sasservername;
%put syshostname:      &syshostname;
%put systcpiphostname: &systcpiphostname;
%put sysncpu:          &sysncpu;
Github repository about-SAS, path: /macro-processor/variables/automatic/hostname-etc.sas
&sysncpu exposes the value of the option cpucount.

Memory structure sizes

%put char width:       &syscharwidth;
%put bits per address: &sysaddrbits;
%put size of long:     &syssizeoflong;
%put size of pointer:  &syssizeofptr;
%put size of unicode:  &syssizeofunicode;
Github repository about-SAS, path: /macro-processor/variables/automatic/memory-structure-sizes.sas

Related to processess

%put sysprocessid   = &sysprocessid;
%put sysprocessname = &sysprocessname;
%put sysprocname    = &sysprocname;
Github repository about-SAS, path: /macro-processor/variables/automatic/process.sas

Enterprise Guide

Variables that are set by Enterprise Guide
%put Client application name: &_clientapp;
%put Client machine name:     &_clientmachine;
%put Project name:            &_clientprojectname;
%put Project path:            &_clientprojectpath;
%put Task filter:             &_clienttaskfilter;
%put Task label:              &_clienttasklabel;
%put User id of client:       &_clientuserid;
%put Username of client:      &_clientusername;
%put EG version:              &_clientversion;
%put SAS host:                &_sashostname;
%put SAS program being run:   &_sasprogramfile;
%put SAS server:              &_sasservername;
Github repository about-SAS, path: /macro-processor/variables/automatic/enterprise-guide.sas

Show all(?) automatic macro variables

All automatic variables can be shown with %put _automatic_;.
Here's a list of some automatic variables:
%macro p(id);
  * put "&id = " &&&id;
  %put "&id = " &&&id;
%mend p;



DATA _null_;
  %p(_CLIENTAPP);
  %p(_CLIENTMACHINE);

  %p(_CLIENTPROJECTNAME);
  %p(_CLIENTPROJECTPATH);

  %p(_CLIENTTASKFILTER);
  %p(_CLIENTTASKLABEL);

  %p(_CLIENTUSERID); 
  %p(_CLIENTUSERNAME);
 
  %p(_SASHOSTNAME);
  %p(_SASPROGRAMFILE);
  %p(_SASSERVERNAME);

  %p(SYSADDRBITS);
  %p(SYSBUFFR);
  %p(SYSCC);
  %p(SYSCHARWIDTH);
  %p(SYSCMD);
  %p(SYSDATE);
  %P(SYSDATE9);
  %p(SYSDAY);
  %p(SYSDEVIC);
  %p(SYSDMG);
  %p(SYSDSN);
  %p(SYSENCODING);
  %p(SYSENDIAN);
  %p(SYSENV);
  %p(SYSERR);
  %p(SYSERRORTEXT);
  %p(SYSFILRC);
  %p(SYSHOSTNAME);
  %p(SYSINDEX);
  %p(SYSINFO);
  %p(SYSJOBID);          /* The PID (process identifier) of the unix process */
  %p(SYSLAST);
  %p(SYSLCKRC);
  %p(SYSLIBRC);
  %p(SYSLOGAPPLNAME);
  %p(SYSMACRONAME);
  %p(SYSMENV);
  %p(SYSMSG);
  %p(SYSNCPU);
  %p(SYSNOBS);
  %p(SYSODSESCAPECHAR);
  %p(SYSODSPATH);
  %p(SYSPARM);
  %p(SYSPBUFF);
  %p(SYSPROCESSID);
  %p(SYSPROCESSNAME);
  %p(SYSPROCNAME);
  %p(SYSRC);
  %p(SYSSCP);
  %p(SYSSCPL);
  %p(SYSSITE);
  %p(SYSSIZEOFLONG);
  %p(SYSSIZEOFPTR);
  %p(SYSSIZEOFUNICODE);
  %p(SYSSTARTID);
  %p(SYSSTARTNAME);
  %p(SYSTCPIPHOSTNAME);
  %p(SYSTIME);
  %p(SYSUSERID);
  %p(SYSVER);
  %p(SYSVLONG);
  %p(SYSVLONG4);
  %p(SYSWARNINGTEXT);

run;
Github repository about-SAS, path: /macro-processor/automatic-macro-variables.sas

_SASWS_

In SAS Studio, &_SASWS_ references the home directory.

See also

macro variables
automatic variables

Index