5 keyboard shortcuts in SAS that will change your life

This post was kindly contributed by The SAS Dummy - go there to comment and to read the full post.

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.

Background
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  */
PROC MEANS DATA=SASHELP.CLASS
  MEAN MODE;
RUN;
 
/* lower case, unassuming */
proc means data=sashelp.class
  mean mode;
run;
 
/* Headline-style initial caps */
Proc Means Data=Sashelp.Class
  Mean Mode;
Run;

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

tags: SAS Enterprise Guide, SAS program editor

This post was kindly contributed by The SAS Dummy - go there to comment and to read the full post.