SAS Display Manager Commands

SAS programmers usually use time-consuming point-and-click methods to accomplish common tasks. For example, when the program completes its run, you need to open a specific dataset to check the desired variable or observation. Have you ever wished that these common tasks can be done automatically? Of course, these tasks had to be accomplished almost automagically. DM commands came to your rescue. A DM command stands for Display Manager Statement. It submits SAS Program Editor, Log, Procedure Output or text editor commands as SAS statements. DM command is very powerful but didn’t get much attention of SAS programmers as they should be. In this post, I’ll introduce 2 DM commands you might not have heard of before.

  1. Usually when you are working with a dataset, you want to see certain columns and not all of them. The following command will show only column A.
    gsub "dm _last_ 'show A;' continue;"
  2. Usually when you are working with a huge dataset, you want to retrieve values in a certain observation. The following command will scroll downward 1116 observations.
    gsub "dm _last_ 'forward 1116;' continue;"

If you don’t want to type commands, here is a hotkey-driven solution. Save the following program(e.g., as /user1/zenga/

%let line=;
%let name=;
%window Tool irow = 10 rows = 15 icolumn = 10 columns = 90 color=white
#3 @18 'To show the desired variable or desired line.' color=blue
#5 @18 'Enter line number:' color=blue
#7 @18 'Enter variable name:' color=blue
#9 @18 'Note: variable name should be separated by a single space.' color=blue
#5 @37 line 15 attr=underline
#7 @39 name 15 attr=underline;
%display Tool;

%macro tool;
%if &line^= %then %do;
    dm _last_ "top" continue;
    dm _last_ "forward %eval(&line-1)" continue;
%if &name^= %then %do;
    dm _last_ "show ""&name""" continue;
%mend tool;


Open one dataset then type below command in command line to assign a VT key to run the code.

keydef "F9" "gsubmit '%inc ""/user1/zenga/"";'"

When you enter the assigned key you will be asked to enter line number or variable name, then you can get desired observation or variable. Window

Xianhua Zeng /
Published under (CC) BY-NC-SA in categories Code  tagged with DM  GSUBMIT 

Previous Parsing Comments from aCRF with Perl Regular Expression
Next Splitting Data Set Based on a Variable