Special automatic macro variables available in SAS Enterprise Guide

You might know about the many automatic macro variables that are available in SAS. They provide plenty of information about the SAS environment, such as the current user (SYSUSERID), the SAS version (SYSVER and SASVLONG), and the operating system where SAS is running (SYSCP and SYSCPL). That information is often useful for your SAS programs and reporting output.

Did you know that SAS Enterprise Guide also generates several macro variables? These provide information about the SAS Enterprise Guide environment, which is often different than the SAS environment when you're connected to a remote SAS workspace.

You can use these macro variables to code various logic tricks into your programs, such as to determine where the current project file resides and assign a library to its path.

Or, even if you don't write SAS programs, you can use the macro variables in task titles and footnotes. For example:


For me, this yields:

Generated by 'Chris Hemedinger' ('sascrh') with SAS Enterprise Guide ''

Here's the complete list of the generated macro variables (as of SAS Enterprise Guide 4.3 and 5.1). These macro variables are also generated in the SAS Add-In for Microsoft Office. You can always find this list in the SAS Enterprise Guide online help, which you access from the help menu. Simply search the keyword index for "macro".

Macro Variable Description
_CLIENTAPP Name of the client application.
_CLIENTMACHINE Client machine node name.
_CLIENTPROJECTNAME The filename for the project.
_CLIENTPROJECTPATH The full path and filename for the project.
_CLIENTTASKFILTER The filter that is defined for the task. You can use this macro variable in the titles and footnotes of the task, so that the filter information is displayed in the title or footnote of your results.
_CLIENTTASKLABEL Label for the current task. This is the text label that is displayed in the project tree and the process flow.
_CLIENTUSERID User ID of the client user.
_CLIENTUSERNAME Full user name, if that information is available.
_CLIENTVERSION Application version, including build number.
_SASHOSTNAME Server node name (IP address or DNS name).
_SASPROGRAMFILE The full path and filename of the SAS program that is currently being run. This macro variable is available only for SAS program files that are saved on the same server on which your SAS Enterprise Guide code is being run.
_SASSERVERNAME Name of the logical server.

And remember, you can easily see all of the available macro variables, along with their current values, by using the SAS Macro Variable viewer custom task.

tags: macro programming, SAS Enterprise Guide


  1. Ronan
    Posted October 12, 2012 at 6:33 am | Permalink

    Hi Chris,

    I tried once to 'leverage' the _CLIENTAPP macro at the autoexec level in order to record which client had launched the workspace session :

    - SAS Enterprise Guide
    - SAS Add In

    Unfortunately, the macro value did not resolve correctly during these early steps of the session initialisation process. The ARM loggers might provide the same information (?) but with overhead and I wanted to avoid that. I also tried to enable the Object Spawner loggers to get the client name but didn't succeed much either.
    I suppose the initial purpose of the automatic macros is to expose their values afterwards, during the report execution so there is probably no workaround following this way. Would the information perchance be available somehow ?


    • Chris Hemedinger Chris Hemedinger
      Posted October 12, 2012 at 7:17 am | Permalink

      Ronan, you might be able to do something by adding a LOG4SAS statement within Tools->Options->SAS Programs: "Submit statements when connect to server". That requires that you touch every client though to set the option.

      EG submits these macro definitions when you run your first "job" after connecting to SAS, which is well after object spawner and the SAS-side autoexec have already done their work.

  2. Ronan
    Posted October 12, 2012 at 11:46 am | Permalink

    Thanks. This requires also to configure user EG profile (AMOOptions.xml) from a shared location (huge task !) but doesn't address the Add-in side of the question since (at least in 4.3), there is no corresponding option for the SAS Add-In. I tried to look in-depth to every option, registry value (%ENTERPRISEGUIDE from sasmacr) or environment variables and I am still unable to find a difference between the Workspace sessions context created by the two clients.

  3. programmeur
    Posted January 4, 2013 at 3:34 pm | Permalink

    This was exactly what I was looking for. Thanks !

  4. Anne O'Keefe
    Posted March 6, 2013 at 12:09 pm | Permalink

    Chris, is there a way to put a macro variable that was generated by a prompt in the program into the title of a report? For example, if there are date prompts in the process flow, I'd like to have those selected dates appear in the report.

    • Chris Hemedinger Chris Hemedinger
      Posted March 6, 2013 at 1:06 pm | Permalink


      If you're talking about a SAS Report that you assemble with File->New Report, then the answer is no. You can't include a macro variable as part of the custom text that you add to a report definition.

      If you're talking about any other simple ODS report, then the answer is Yes -- you can reference the macro variable (generated by the prompt) in a TITLE statement.

      • Tracy
        Posted July 24, 2014 at 7:59 pm | Permalink

        I am trying to use date macros defined in the program in my EG Custom Report. However, when I put them in the header or footer, they print literally instead of being resolved. Is there a way to resolve them? If not, I would like to set up a program that would generate my report title, and then include that output in my Custom Report. Can you suggest a procedure that I could use to do this? I tried proc print, but would like results that look a little more like a report title than a table.

        • Chris Hemedinger Chris Hemedinger
          Posted July 28, 2014 at 9:31 am | Permalink

          Tracy, you could try the ODS TEXT statement. It doesn't give you the same flexibility for formatting, but you can get your macro variables to resolve in your custom report. The ODS TEXT item appears as a separate item in your SAS Report output for the custom report. Example:

          ods text="My SAS Enterprise Guide version is: &_CLIENTVERSION.";
          proc print data=sashelp.cars;
  5. Anne O'Keefe
    Posted March 8, 2013 at 4:06 pm | Permalink

    Thank you! With the help of your SAS Macro Viewer custom task I was able to select the exact promt selection for the title that I wanted. The prompt macro variables showed up in the macro viewer after I created them using the prompt manager. My date range prompt generated 6 macro variables: min, max, min_label, max_label, min_rel, and max_rel.
    Thank you again. I will be following your blog.

    • Chris Hemedinger Chris Hemedinger
      Posted March 8, 2013 at 4:13 pm | Permalink

      Anne, excellent! That was my plan all along - to get more followers.

  6. Phillip Coulson
    Posted October 28, 2013 at 7:33 am | Permalink

    Chris, Are you aware of a generated macro variables that will resolve to the name of the Process Flow/Project Tree?

    • Chris Hemedinger Chris Hemedinger
      Posted October 28, 2013 at 8:22 am | Permalink


      No, sorry - there isn't a macro variable automatically assigned for that. It would be very easy to create a custom task that initialized that though...would that be of interest?

      • Phillip Coulson
        Posted October 28, 2013 at 1:53 pm | Permalink

        Hi Chris, that would you very useful.can you advise how I might go about doing that?

        It is probably worth adding that I use EG remotely via client software.and so installing an add-on such as the Sas macro viewer custom task mentioned above may not be possible.thanks, Phil

        • Chris Hemedinger Chris Hemedinger
          Posted October 28, 2013 at 3:06 pm | Permalink

          Phillip, I can put together a quick example -- BUT it will require that you place it on the PC that is running SAS Enterprise Guide. Custom tasks must be "co-located" with the EG application. You don't typically need admin privileges, but you would need to be able to place the custom task DLL in %appdata%\SAS\EnterpriseGuide\5.1\Custom.

  7. Shubha Karanth
    Posted April 8, 2015 at 9:23 am | Permalink

    Hi Chris,

    I need to run an embedded SAS program file in EG using the %include statement. So, How can I extract the path of this embedded program file?

    Thank you.

    • Chris Hemedinger Chris Hemedinger
      Posted April 8, 2015 at 9:32 am | Permalink


      You cannot use %INCLUDE to reference a program that is embedded in the EG project. However, if you need that code to be submitted at the beginning of your project, try the Autoexec process flow. You can designate a set of tasks to run automatically when you open your project, which can help to set up libraries or macros that you know your project relies on.

  8. Cedric
    Posted April 7, 2016 at 12:09 pm | Permalink

    Sometimes the _sasprogramfile macro variable is blank. I have SAS EG and it is connected to three versions of SAS 9.2, 9.3 snd 9.4 How can I populate this variable 100% of the time?

    • Chris Hemedinger Chris Hemedinger
      Posted April 7, 2016 at 4:04 pm | Permalink

      This macro var is populated only if the program is linked to a file associated with the server you're running on, and not just "embedded" in the project. In that case you could sub in the value of %_CLIENTTASKLABEL.

      %macro isBlank(param);
      %mend isBlank;
      %macro assignfilename;
      %if not %symexist(_sasprogramfile) or %isblank(&_sasprogramfile) %then
      %let _sasprogramfile=&_clienttasklabel;

      %put &_sasprogramfile;

  9. Vinay Venkatswamy
    Posted September 21, 2016 at 2:23 pm | Permalink

    Hi Chris,

    I was wondering if EG could record the full path to the program file, as it would in PC SAS.
    &_sasprogramfile would just give me the program file's name. But, is there a way it would record the full path to the program file?


Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>