Special automatic macro variables available in SAS Enterprise Guide

19

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.

Share

About Author

Chris Hemedinger

Director, SAS User Engagement

+Chris Hemedinger is the Director of SAS User Engagement, which includes our SAS Communities and SAS User Groups. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies

19 Comments

  1. 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 on

      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. 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. Anne O'Keefe on

    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 on

      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.

      • 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 on

          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;
          run;
          

  4. Anne O'Keefe on

    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.

  5. Phillip Coulson on

    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 on

      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 on

        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 on

          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.

  6. Shubha Karanth on

    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.
    Shubha

    • Chris Hemedinger
      Chris Hemedinger on

      Shubha,

      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.

  7. 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 on

      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); %sysevalf(%superq(param)=,boolean) %mend isBlank; %macro assignfilename; %if not %symexist(_sasprogramfile) or %isblank(&_sasprogramfile) %then %let _sasprogramfile=&_clienttasklabel; %mend; %assignfilename; %put &_sasprogramfile;

  8. Vinay Venkatswamy on

    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?

    Thanks,
    Vinay

Back to Top