5 keyboard shortcuts in SAS that will change your life


Okay, given the title of this article, I might be overselling the content a bit. Read on to see if your life will be transformed.

I've just returned from SESUG, and this question came up during one of the presentations. While this tip might seem basic, it was news to many of the people in the room, so I think it's worth sharing here.

The "old school" style of SAS programming uses upper case for all SAS keywords. But, unlike many newer programming languages, the SAS language is not case-sensitive. These three programs are exactly the same in the eyes of SAS:

/* This is your grandpa's SAS program */
/* Before the shift key was invented  */
/* lower case, unassuming */
proc means data=sashelp.class
  mean mode;
/* Headline-style initial caps */
Proc Means Data=Sashelp.Class
  Mean Mode;

Even though the uppercase style is old-fashioned, it's the style used by SAS Enterprise Guide tasks. When users copy and paste these generated programs into their own code projects, they often want to convert the keywords to lowercase. Do you need to retype the program? Of course not. Any program editor worth its salt offers basic reformatting features, and the SAS program editor is no exception.

Here are 5 examples of quick keystrokes that can save you time.

Convert case
Convert selected text to upper case: Ctrl + Shift + U
Convert selected text to lower case: Ctrl + Shift + L

Quick commenting
Wrap selection (or current line) in a comment: Ctrl + /
Unwrap selection (or current line) from a comment: Ctrl + Shift + /

Hyperjump to a line
Go to line: Ctrl + G (prompts for a line number)
Be sure to turn on Show line numbers in Program->Editor Options, or you'll be navigating blind!

Jump to the "end of scope"
Move caret to matching parenthesis/brace: Ctrl + [, Ctrl + ]
Move caret to matching DO/END keyword: Alt + [, Alt + ]

There are dozens of other shortcut keys and commands available in the program editor. In SAS Enterprise Guide, you can view them all by selecting Program->Enhanced Editor Keys. From this window you can customize the keypress behaviors to your liking, and you can also combine commands and assign them to new keys. If you're a "keyboard person", then you'll want to visit this window and explore. Be sure to click "Include commands without key assignments" to see the full list of available commands.

There are many useful commands that don't have a default key mapping. For example, one very handy command is "Sort selected lines", which will resequence the selected lines into ascending alphabetical order. If that's an operation you need to do frequently, click the Assign Keys button to pick a key sequence as a shortcut.

You can also combine commands with editor macros. For example, would you like a keystroke that can add a date/time stamp as a program comment? Simple! Select Program->Editor Macros->Macros. Then click Create... to build a new sequence. Add the commands you want to automate, and then finish by assigning the new macro to a key sequence. To insert a commented date/time stamp, these are the commands to add:

  • Insert current date and time
  • Comment the selected lines with line comment

Here's what the window looks like:

I assigned Alt+Shift+D to this command, and when I press it just now I get:

While my instructions here apply to SAS Enterprise Guide, this is all available in SAS for Windows when you use the Enhanced Editor. There are several conference papers on the topic: here's one from Art Carpenter.

See also

Take SAS program editor abbreviations to the next level
Hope for ugly programs: the SAS Enterprise Guide code formatter


About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. 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.  He also hosts the SAS Tech Talk webcasts each year from SAS Global Forum, connecting viewers with smart people from SAS R&D and the impressive work that they do.


  1. Chris,

    Thanks for the helpful tips on E-Guide.

    Now here is a question and hope you have a solution to it.

    I am a 30+ year SAS veteran and have mostly done all of my coding in Base SAS using DM or Ultraedit and save my code as external sas programs. If I was to find where a particular set of code or variable names reside within a directory, I can do a global search across all of my programs to find this section of code or variable names and get a list of programs where they occur.

    However, can you do this with EG - what ever version? We are migrating to the newest version of SAS 9.4 with the newest version of EG. My biggest fear is not being able to do a global search OUTSIDE of EG to find certain code, variable names, or text strings to find out which EG projects contain what I am looking for.

    Does the newest version of EG have this capability? That is search OUTSIDE of EG to find a text string? And, I mean NOT to have to convert EG projects to external files just to find this string.

    EG is GREAT for development - BUT has SAS developers thought how to maintain EG code on a global basis? Maintenace is a BIG factor in the IT world as things change ALL THE TIME - and so code has to change as well.

    Hoping you and SAS have a solution to this for all of us that have to maintain existing EG projects.

    Charles Patridge

  2. Thanks for this.
    One thing I find annoying thouhg is that CTRL + O opens a project, and not a file (which is what I useually needs). You can change the programming shortcuts, but apparantly not the 'Edit' ones ?

    • Chris Hemedinger
      Chris Hemedinger on

      I often recommend the AutoHotkey tool (free) to people who want to map keys to certain operations. You probably cannot replace an existing hotkey built into the app, but you could map your own new preferences.

  3. Good day please I need the keyboard shortcut for submit. That is you filled a form and you have to click on submit to update the form but the submit button on the web page is no longer functioning, so what is the keyboard shortcut so I can use that one.

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Sam -- not really SAS-related... But usually ENTER is the default key to submit a web form. However, if the Submit button on the form isn't working -- the keyboard method probably isn't going to help. Most likely there is a web page issue/connection problem.

  4. Dennis Fabrizio on

    I've been looking everywhere for a list of commands for creating additions to the tool bar. For example I want to customize the tool bar to include an icon to "mark/bookmark" a single line in the enhanced editor in order to return to that line. Using ctrl F2 will do this, but I would like to add it to the tool bar. Is there a source that list these types of commands?

  5. By pure keyboard blundering I just discovered that if I have a line highlighted and type Cntl ?, the line will be commented out. This appears to work in both EG and DM. I have not personally assigned any keyboard shortcuts to any keys.

    • Chris Hemedinger
      Chris Hemedinger on

      Nat, that's right -- actually the key combo is Ctrl+/ (shares with the ? on US keyboards) for comment out, and Ctrl+Shift+/ for "uncomment" the selection. That's built in goodness, right there.

    • Chris Hemedinger
      Chris Hemedinger on

      "Run Selection" is mapped to F3 (when you have a selection -- otherwise it runs the entire program). Open Log and Open Last Data Set are not mapped to keys and there isn't a way to do this natively in EG, but some customers have had success with AutoHotkey -- a free application that allows you to map keyboard shortcuts to any operation (or series of operations) for any Windows application.

  6. Hi Chris

    Are there shortcut keys for the follwoing in SAS eg 5.1:
    - Run a Selection
    - Open Log
    - Open last dataset created

    I really need these. They are easy to assign in Base SAS but I cant seem to find them in the enhanced editor on SAS EG.

  7. Hello,
    does anyone know how to highlight ALL the sas code in the editor via the keyboard?? I can't remember how to do it! thanks! Jill

  8. Hello,

    Does anyone know how to switch from program to output data by using short keys in SAS EG?

    Thanks! Kirsten

    • Chris Hemedinger
      Chris Hemedinger on

      Use Ctrl+TAB to cycle among Program, Log, and Output (including data and ODS). See all of the documented keyboard shortcuts in the SAS Enterprise Guide help -- there's a bunch of them!

    • Chris Hemedinger
      Chris Hemedinger on

      Do you mean increase the font size? That's mapped to Ctrl+ (and reduce is set to Ctrl-). There isn't a way to reassign it. Or do you mean "maximize" the editor so it takes the entire app space? That's set to Ctrl+M -- again, no way to reassign it.

  9. Those 5 keyboard shortcuts do not Change my life. Why can't you just go and take care of some basic autocomplete Features?! Get variables from a dataset - sometimes works, mostly it doesn't. Helpful descriptions?! Not with SAS. Sorry, but your shortcuts are ridiculous. Your strategy "sell expensive product - make it diffficult to use - then sell trainings" does not work anymore. This is one reason why we are switching to python.

  10. Hi Mr Shortcut,

    No, we will not switch to Notepad++. Please fix your software by yourself.
    However, you can indeed help us with a shortcut here:
    Let's say we have a data set with variable called 'gender', which should be a domain, which allows the values 'male' and 'female'.

    a) How do I create a domain?
    b) Which is the shortcut to get possible values of that domain at that point in code:
    data example2;
    set example1;
    if gender eq [WHAT SHORTCUT TO GET THE LIST]


    • Chris Hemedinger
      Chris Hemedinger on

      Hi Andrej,

      The program editor cannot list the domain of values in a variable. As you can imagine, that can be a very expensive operation for large data sets, and a shortcut key that launches that could get you into trouble. (Getting table names and variable names makes use of column metadata, which doesn't require scanning all of the rows in a data set.)

      What you refer to as a "domain" is often implemented in SAS as a format: a defined set of values/ranges and their labels that are used for display or categorization. You can use SAS formats as a way to help ensure data quality and identify values that don't comply with a given set of valid values. And while less commonly used, it's also possible to define integrity constraints with PROC DATASETS.

      That said, there are are number of ways to find the list of distinct values using SAS Enterprise Guide tasks or SAS procs. For example, check the Describe->Characterize Data task, Describe->One-way Frequencies, or the Query Builder DISTINCT summarization. (PROC FREQ or PROC SQL for a coding approach.)

      • Thanks for the info and thanks for the fast response.

        "The program editor cannot list the domain of values in a variable. As you can imagine, that can be a very expensive operation for large data sets, and a shortcut key that launches that could get you into trouble"

        Maybe you misunderstood that I want to see all values in the dataset (which, indeed, could be millions). Actually, I was trying to say something else: I would like to have a shortcut here that shows a list consisting only of values of the underlying domain. In the example, 'male' and 'female'. IMHO, showing a small list of values of a domain should not have that much an impact of the performance.
        Maybe you want to check, how they implemented that feature in python (it's open source).

        Thanks & Regards,

        • Chris Hemedinger
          Chris Hemedinger on

          It's my understanding that Python, like SAS, has a best practice for encoding categorical variables to prep them for analytics. In SAS, the practice often involves SAS formats. In Python, you might use label encoding or a similar approach. That's good for categorical values (like "Cylinders" in car data) but not as practical for continuous variables (like "TransactionAmount"). The challenge in SAS is that the number of values in a domain is UNKNOWN -- that is, it's not part of the data set metadata. Some SAS tools (like SAS Visual Analytics) will quickly generate that information for you, but the SAS programming language (and the IDEs that support it) cannot do that efficiently. SAS DATA steps and PROC steps are compiled when you submit them, not interpreted on the fly. The program editor/IDE can do only so much to predict the valid contents of a variable before you run a step.

          All of that to say that some of the conveniences you've learned in Python don't apply to SAS. And if you were coming to Python from having a lot of SAS experience, you would find yourself missing some of the SAS features you've become used to.

  11. Quick question on EG please, I have a set of code which i use very often, I would like to create a shortcut where if i one write one word and other code should be auto-completed(like MS word). I am not sure if we have this functionality in EG?

  12. Hi Chris,

    Thanks for sharing those useful shortcuts. Charles Patridge, the first replier in this posting, mentioned something like global search in Base SAS. Does that mean there is a way to search a certain string across multple SAS code files at once? I would like to know this. Thanks.

    • Chris Hemedinger
      Chris Hemedinger on

      Not natively in SAS Enterprise Guide, unless all files are loaded into the EG project. (Then you can use the Project Search feature.) I usually use Notepad++ or VS Code for this type of thing, or command-line grep.

  13. Hi Chris,

    Thanks for valuable informations. Sometimes, Quick commenting (Ctrl + / and Ctrl + Shift + /) doesn't work. The '¿' was typed instead when I entered Ctrl + Shift + /

    • Chris Hemedinger
      Chris Hemedinger on

      This could be a keyboard difference. Different regions have different keyboards that may override these. In v8.2 you can customize more of your keyboard actions.

  14. Hi Chris,

    Thanks so much for this post! Is there a way to minimize/collapse all procs in a program at once? I'm hoping to just "shrink" my code so I can scroll through the first line of each proc faster.

    Thanks so much!

    • Chris Hemedinger
      Chris Hemedinger on

      Yes! Ctrl+Alt+Num- (that's Ctrl and Alt keys, along with the minus key on the Num pad) will collapse all sections. Likewise, Ctrl+Alt+Num+ will expand them all.

  15. Izabella Peszek on

    Thank you for very useful tips. Could you tell me if there is a way to "run to cursor"? That is, submit the code up to the cursor location? Thank would be very useful thing to have :-). If not possible now, would you consider adding this feature in future versions?

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Izabella, this would be a combo of these actions I think:
      - Extend selection to start of document (Ctrl+Shift+Home by default)
      - Submit selected (F3)

      Unfortunately, I don't think the Submit Selected can be added in an editor macro combination, so I don't think there is a built-in method to assign to a single key.

Leave A Reply

Back to Top