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:

Generated by &_CLIENTUSERNAME (&_CLIENTUSERID) with SAS Enterprise Guide &_CLIENTVERSION

For me, this yields:

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

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

12 Comments

  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 ?

    Ronan

    • 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

      Anne,

      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.

  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

      Phillip,

      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.

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> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>