Ten SAS Enterprise Guide program editor tricks

28

If you spend a lot of time in SAS Enterprise Guide (as I do), you probably get to know its features pretty well. But we don't always take the time to explore as we should, so there might be a few golden nuggets of editor knowledge that have escaped you so far. Here are 10 program editor features that I've found essential while writing, editing, and debugging SAS programs. How many of these do you already know and use?

1. Turn on the line numbers

We programmers like to count lines of code. The SAS log often uses line numbers to reference problems in WARNINGs and ERRORs. So of course, you should have line numbers displayed in the program editor. But they aren't on by default. Go to Program → Editor Options and select "Show line numbers" to turn them on.

line numbers

2. Get the tabs out (or leave them in)

Tabs or spaces? Your choice here can have a significant effect on your earning potential, and perhaps even on your love life. Most code editors have options that support your choice, regardless of which camp you choose. SAS Enterprise Guide offers these:

  • Tab size - width of a tab character, represented in number of spaces. Default is 4, but I like to use 2 as it makes my program lines less wide.
  • Insert spaces for tabs - when you press the TAB key, don't add a TAB character but instead add the specified number of space characters.
  • Replace tabs with spaces on file open - a perfect passive-aggressive option when working with team members who disagree with your TAB world view. This option will change TAB characters to spaces when you open the program file. If you must retain the TAB characters...well, my main advice is do not rely on TAB characters in your code file. But if you must for some crazy reason, don't select this option and sign a pact with your teammates for the same.

tabs vs spaces

3. Define abbreviations for commonly used code

The most common code snippet that I reuse is a LIBNAME statement that points to my project data. To save on typing and mistakes, I've saved this as an editor abbreviation. When I begin to type the alias I've assigned to the snippet, the program editor offers to complete it for me. The custom abbreviation is presented along side all of the other built-in syntax suggestions.

abbrev animation

See more about editor abbreviations in this article.

4. Let the editor format your code

As shown in the vigorous "TABS vs spaces" debate, programmers care deeply about how their code is formatted. Individuals and teams adopt various standards for line breaks and indenting, and these are usually particular to the programming language. In general, SAS doesn't care how your code is laid out -- statements are delimited by semicolons, and that's the only cue that SAS needs. However, your teammates (and your future YOU, rereading your code) might appreciate something a little more readable.

Press Ctrl+I to format your entire program, applying some reasonable readability rules to indent code lines with conditionals and looping logic. Or select just a portion of the program and press Ctrl+I to affect a smaller part of the program. You can adjust some of the formatting rules by visiting Program → Editor Options, the Indenter tab.

autoformat code

5. Zoom out for the big picture

Some SAS programs are long -- hundreds (or thousands!) of lines of code. Sometimes it's helpful to get a birds-eye view of your code to understand its structure and to help you navigate. The Zoom feature is super helpful for this. Simply press Ctrl+- (control-minus) until you get the view you need. Press Ctrl++ (control-plus) to zoom back in, or press Ctrl+0 to get to the 100% view.

This trick works for SAS logs as well, and also data sets and ODS output (including text listing, which uses the program editor in a special mode for viewing SAS output).

zoom out

6. Change the program editor font

Want to waste an afternoon? Search the Internet for "best font for programmers" and experiment with all of the results that you find. I discovered Consolas (built into Microsoft Windows) a decade ago, and I've yet to find anything better. I use it for all of my "fixed font" needs: programming, terminal windows, command consoles, etc. But you can choose your own favorite -- just don't feel that you're stuck with the default "Courier" that seems to be standard issue.

Change your font in Programs → Editor Options, Appearance tab. You'll find lots of elements that you can tweak for typeface, size and color.

7. Select columns of content with block selection

Even though column block selection -- also known as "Alt+Select" -- is a standard feature in most advanced text editors, many programmers don't know about it. It's the perfect trick for selecting just a few columns of your text without including the content that's on the rest of the line. In SAS programming, this can be handy for selecting columns of values from the text listing output and pasting somewhere else, such as into a DATALINES block. It takes a little practice to master the Alt+Select, but once you do you'll find all sorts of uses for it. To get started, simply hold down the Alt key and click-drag to highlight a vertical column of text within the editor.

column selection animation

8. Find (and replace) using regular expressions

Regular expressions are a powerful, if confusing, method for finding and replacing text that matches certain patterns. The Find/Find and Replace window in SAS Enterprise Guide supports "Regular expression search" as a checkbox option.

Here's an example. Suppose I wanted to find all occurrences of 3 numbers after the thousands separator (comma) at the end of each data line -- and I wanted to turn those digits into zeros. (I don't know why--but just stick with me here.) A regex pattern to match this is ",\d\d\d\n" (comma, followed by 3 occurrences of numeric digits, followed by a line ending). Here's an animation of this in action.

regex replace animation

For more, select Help→SAS Enterprise Guide help and search for "regular expressions". The help topics contain several examples of useful patterns.

9. Scroll just part of your document using a split view

Do you find yourself scrolling back and forth in your program view? Trying to remember what was in that DATA step at the top of your program so you can reference the proper variable in another part of your code? Instead of dealing with "scrolling whiplash", you can split the program editor view to keep one part of your code always visible while you work on another code segment that's hundreds of lines away from it.

split view

There are several ways to split your view of SAS code, log output, and listing. Check out the article here for details.

10. Break out to your other favorite editor

Please don't tell anyone, but I have a secret: SAS Enterprise Guide is not my default application associated with .SAS files. When I double-click on a .SAS file in Windows Explorer, I like to use Notepad++ to provide a quick view of what's in that program file. Don't get me wrong: I use SAS Enterprise Guide for all of my serious SAS programming work. With syntax suggestions, color coding, built-in DATA step debugger, and more -- there just isn't a better, more full-featured environment. (No, I'm not trying to troll you, diehard SAS display manager users -- you keep using what makes you happy.) But Notepad++ has a deep set of text editing features, and sometimes I like to use it for hardcore find/replace functions, deeper inspection of special characters in my files, and more.

You can launch your program into your other favorite editor from SAS Enterprise Guide. Simply right-click on the program node in your process flow, select Open → Open <program name> with Windows Default. And make sure your other editor is registered in Windows as the default "Open with" action for SAS programs. Note: this trick works only with SAS programs that you've saved locally on your Windows file system.

Open with default

See also: How to use Notepad++ as your SAS code editor.

More than editing -- this is your workbench

The program editor isn't just about "editing programs." It's also the launchpad for several other programmer-centric features, such as debugging your DATA step, comparing your SAS programs, viewing program history and source control, and more. If you use SAS Enterprise Guide, take the time to learn about all of its programming features -- you'll become a more productive programmer as a result.

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

28 Comments

  1. Lots of great tips and reminders. Love all the video snippets too! Thanks for sharing... Oh and I also read that your preference is tabs over spaces... Does that mean you take 2 steps at a time like the guy in the video you shared? (hilarious video by the way) :-)

  2. David Moors on

    Silicon Valley (video clip) is just THE best TV program :)

    I'm similar to Chris in that I use notepad++ to view local SAS files and for quick editing. The compare plugin in notepad++ is also very handy for comparing SAS files, especially on a remote server.

  3. Chris Umphlett on

    I don't see a way to split the program. Looking at the article to which you linked, there is no "split" option in the menu, nor do I get a split handle when I hover near the edge of the program editor. I'm using SAS EG 7.13HF5

    • Chris Hemedinger
      Chris Hemedinger on

      Right-click in the program editor, select Split->(Stacked | Side by Side | Both) from the menu. Not sure why this wouldn't be there for you. Do you not see the Split menu when you right-click in the code view?

  4. As I had alluded in Rob's post, tabs in SAS programs on Windows machines can cause issues in batch versus interactive submissions. Our shop just learned the hard way. I am not sure if this matters for EG or if those programs port.

  5. Hi Chris,

    I have a question about EG workflows:

    I have a workflow in a SAS EG project. I would like to know if it's possible to condition the execution of a workflow
    to the value of a a macrovariable. For example if &var=1 -> execute all the branch of the workflow, else don't execute.
    I know how to do something similar with sas base code using macros, but I would like to know if it is possible in
    workflows of SAS EG projects.

    Thanks in advance

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Juan, yes, it's possible. You can assign a Condition to any node that runs (task or program). When the Condition is checked, EG will make a decision about whether to run down a certain branch or stop processing. And the condition can be based on the value of a macro variable. For more information, look in the SAS Enterprise Guide help -- look for "condition" (or perhaps "condición" if you're running EG in Spanish).

  6. Thank you Chris, that's what I was looking for.
    As yo said "condición" because I run in Spanish
    As you know in Spain there are a lot of sas users.

  7. It is amazing, best I can tell, that EG has no built in way to search the entire project for a text string.

    • Chris Hemedinger
      Chris Hemedinger on

      It does! This was added in EG 7.1. Find the "Search Current Project" item in the upper right of the EG application window.

  8. Pingback: Using Notepad++ as your SAS code editor - The SAS Dummy

  9. Peter Crawford on

    Once upon a time in a g.........far far......
    I appreciated being able to pipe a string of commands into the editor (the days of command driven editors)....
    SAS still offers that functionality in one of its editors. (Use the %macro language to package complex strings of commands, and draw info from the SAS environment dictionary)
    When could we look forward to something similar in EGs editor?
    Or is that functionality why you like Notepad++?

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Peter,

      The EG editor does pull info from the SAS environment to support autocomplete for libnames, data sets, and variable names -- so the wiring is there. However, none of that is available to you for customized actions. I think if you provided some use cases for the types of tasks you're trying to accomplish, the team might be able to consider new features.

  10. Hi Chris,
    i think that all these options are stored in the registry file. But as we use Citrix to lauch SEG 7.1, our users are loosing their customizations at the end of their session.
    Is there a way around this problem ?

    • Chris Hemedinger
      Chris Hemedinger on

      They are stored in the registry -- in the user-specific area. Ideally, your Citrix environment would store these for the user profile. I'm certain there is a way to allow that, as many apps use the registry for customizations. But that's a Citrix admin question.

  11. Andrea Zimmerman on

    Is there a way to have two programs from the same project open at the same? The same way you can get the split view to view two places in the same file, I'd like to see two different programs in those panels.

  12. You can set up Notepad++ to execute look like the SAS editor as well. You can also setup Notepad++ to execute SAS, so you actually never need to enter the SAS environment.

  13. ALAN CHURCHILL on

    Chris,

    Any way to have quick code snippets, in EG, like you can do in Visual Studio? Example, drag code to a Toolbox on the left and have it readily available? This is in addition to #3 above.

    There seems to be a variant in SAS Studio but, IMO, not as convenient as the drag and drop. You always have to rename them in VS so the SAS method saves 1 step in one light.

    Thanks,
    Alan

    • Chris Hemedinger
      Chris Hemedinger on

      Alan, the only thing that EG supports are abbreviations (renamed to snippets for consistency).

    • Chris Hemedinger
      Chris Hemedinger on

      Not exactly. But you can add Snippets (bits of code that you assign as an abbreviation). And you can "pin" program files that you open to the recent list so they are always on top and visible.

Back to Top