Jane Eslinger

2月 172018
 

Keyboard MacrosIt is not laziness—it is efficiency!!! Programmers are often called lazy; we even call ourselves lazy. But we are not lazy, we are just being efficient. It makes no sense to type the same code over and over again or use more keystrokes than are absolutely necessary.

Keyboard Macros

You might not have heard of keyboard macros. Or, perhaps, you do not know how they could help you. I am very fond of keyboard macros; let me show you why!

In SAS Technical Support, supporting the SAS® Output Delivery System (ODS) and Base SAS® procedures, I often use the same statements to set up test programs. For example, I want any style templates that I create to go into the Work directory. I also use the same data set name all of the time. I have created keyboard macros for the statements, data set names, and options that I use daily.

When I press Ctrl+Alt+w, the following is inserted into my program:

ods path(prepend) work.templat(update);

When I press Ctrl+Alt+p, the following is inserted into my program:

sashelp.class

How did I do that? I recorded a keyboard macro that contains the code that I want. Then, I assigned keys that insert the code when I press them.

Here are the steps for recording your very own keyboard macro in the SAS Enhanced Editor:

1.  Select Tools ► Keyboard Macros ► Record New Macro.

2.  Enter the code that you want to be your new keyboard macro. Consider typing slowly because any backspaces that you use are included in the recording.

3.  After you are done entering text, you need to tell SAS to stop recording. Select Tools ►Keyboard Macros ►Stop Recording.

4.  A pop-up dialog box appears that lets you give the new macro a name and assign the keys that you want to be associated with the macro. You can set the key combination that make sense to you. Just make sure that you do not use a combination that is already assigned to another macro.

Now, whenever you need to insert that piece of code, just use the keys that you assigned!

In SAS® Enterprise Guide®, you can find keyboard macros under Program ► Editor Macros, instead of the Tools drop-down menu. The recording and key assignment steps are the same in both applications.

You can also create keyboard macros that perform tasks.

The Macros selection opens a pop-up dialog box that contains a Create button.

Clicking Create opens another dialog box.

With the Categories option set to All, you can see all of the commands that are already available. Moving these over to the Keyboard macro contents section enables you to build a macro that performs a task that you need to accomplish on a regular basis.

For example, I have combined these commands to select a whole block of code, like from the PROC statement down to the RUN statement.

Keyboards macros are available in the Enhanced Editor in Display Manager SAS (DMS) and in SAS Enterprise Guide. They cannot be used with the Program Editor in DMS or in SAS® Studio.

You can export and import keyboard macros. The file created when you export has the .kmf extension. You can find the options for importing and exporting in the Macros dialog box. You can share your keyboard macros with your friends, or just to keep them as a backup copy in case you need to reinstall SAS.

For more information, see the Using "Keyboard Macros" section in "Using the Enhanced Editor."

Function Keys

You have probably used the F8 key to submit your program, or the F4 key to recall your last program. Did you know that you can set or change those instructions?

In the Enhanced Editor, you can get the list of assigned keys by entering keys into the command bar or by selecting Keys under Tools ► Options.

I test a lot, which means that I am routinely clearing the log, the results viewer, and the output window. I have assigned an F key, F12, to clear everything and bring the focus back to the Enhanced Editor (see the commands in the screenshot below). I have to press only one key to clean everything up! I use the F12 key over and over again.

The keys that you assign in DMS are valid from both the Enhanced Editor and the Program Editor.

SAS Enterprise Guide includes a large number of commands by default. A lot of them already have keys assigned, but some do not. You can see the list of the commands and their assigned keys by selecting Enhanced Editor Keys under the Program drop-down menu.

Currently, it is not possible to modify the function keys in SAS Studio. However, a number of keys are already defined that you might find useful. You can see the function key shortcuts by clicking the question mark in the upper right, choosing SAS Studio help, and then selecting the option for Accessibility Features. Here are links to additional resources:

I highly recommend using keyboard macro and function keys. Why type the same thing over and over again? Increase your productivity by handing the repetitive tasks over to SAS.

Efficiency at your fingertips: Keyboard macros and function keys was published on SAS Users.

4月 182017
 

Ok, so you know how to create multiple sheets in Excel, but can anyone tell me how to control the name of the sheets when they are all created at once? In the ODS destination for Excel, the suboption SHEET_INTERVAL is set to TABLE by default.  So what does that [...]

The post How to control the name of Excel sheets when they are all created at once appeared first on SAS Learning Post.

4月 072016
 

When you’re making a report, how do you choose which procedure to use?  The answer is – it depends. It depends on: whether you are doing an ad hoc analysis or creating a final report that many people will see whether you will run statistical tests with your data or […]

The post PROC REPORT versus other base SAS procedures appeared first on SAS Learning Post.

7月 112014
 

Did you inherit code that was written eons ago?  Do you find old programs to copy the PROC REPORT code and then simply change the variable names for your new program?  Have you wondered what all of those options do?  Do you ever send output to the Listing destination (the Output Window) anymore?

If you said yes to any of the questions above -- clean it up!  PROC REPORT has been around forever, but it has changed and evolved over the years to facilitate the creation of nicer looking output, specifically in non-Listing ODS destinations.

There are a number of options that are only valid in the Listing destination. Do you really need them? If you aren’t using that destination, then remove any outdated options from your SAS programs. Here’s a list by statement in the REPORT procedure:

PROC REPORT statement: outdated options

BOX NOWD/NOFS *
COLWIDTH= PANELS=
FORMCHAR= PS=
HEADLINE PSPACE=
HEADSKIP SPACING=
LS= WRAP

Nonwindowing mode became default in 9.4.

DEFINE statement: outdated options

CENTER * RIGHT *
FLOW SPACING=
LEFT * WIDTH= **

* In the Listing destination the LEFT, RIGHT, and CENTER options change the justification of both the headers and the data.  In other ODS destinations these options change only the justification for the data.  Instead of these options, it is highly recommended that you use the JUST= attribute within STYLE(COLUMN)= and STYLE(HEADER)= to change the justification.

** The standalone WIDTH= option is for Listing.  WIDTH= within a style specification, like STYLE(COLUMN)=[WIDTH=1IN], is for other ODS destinations.

BREAK statement: outdated options

DOL SKIP
DUL UL
OL

RBREAK statement: outdated options

DOL SKIP
DUL UL
OL

You can leave these options in, but why?  Make your PROC REPORT code more readable for yourself and anyone else who picks it up.  

 

tags: Problem Solvers, PROC REPORT, SAS Programmers
3月 142014
 

Like every SAS procedure, PROC REPORT generates error messages that are specific to that procedure.  Some of these errors are easier to understand and work around than others.  In this blog post, I show six of the trickiest errors, explain what might be causing the error, and give advice for how to circumvent it.

#1.  ACROSS variable not defined

proc report data=sashelp.class;
column sex, height;
run;

ERROR: There is more than one ANALYSIS usage associated with the column defined by the following elements.

A comma in the COLUMN statement indicates that you want a variable to be used as an ACROSS variable, i.e. one variable stacked on top of another.  This error will occur if your program doesn’t include a DEFINE statement with a usage of ACROSS.

Circumvention: Add a DEFINE statement for the ACROSS variable.

proc report data=sashelp.class;
column sex, height;
define sex /across;
run;

#2.  DISPLAY or GROUP variable needs its own column

proc report data=sashelp.class;
 column sex, height;
 define sex /across;
 define height /group;
run;

ERROR: A DISPLAY or GROUP variable above or below an ACROSS variable requires that there be an ORDER, GROUP, or DISPLAY variable in the report that is not above or below an ACROSS variable.

Often a report requires an ACROSS variable with a character and an analysis variable underneath it. PROC REPORT can create this report, but it has to have a DISPLAY or GROUP variable that is its own column.

Circumvention: Add a grouping variable and place it before the ACROSS variable on the COLUMN statement. The new variable can be defined as NOPRINT so that it will not be seen in the report.

data class;
 set sashelp.class;
 dummy=1;
proc report data=class;
 column dummy sex, height ;
 define dummy /group noprint;
 define sex /across;
 define height /group;
run;

#3.  Variable below ACROSS variable defined as DISPLAY

proc report data=sashelp.class;
 column age sex, height;
 define age /group;
 define sex /across;
 define height /display;
run;

ERROR: There is no statistic associated with XXXX.

This error message is generated when the only variable below an ACROSS variable is defined as DISPLAY.

Circumvention:  Change the DISPLAY variable to be GROUP or add the N statistic after the ACROSS grouping on the COLUMN statement.

proc report data=sashelp.class;
 column age sex, height;
 define age /group;
 define sex /across;
 define height /group;
run;

#4.  Multiple summary rows on the same variable or location

proc report data=sashelp.class;
 column sex sex=sex2 weight;
 define sex /group;
 define sex2 /group;
 break after sex /summarize;
 break after sex2 /summarize;
run;

ERROR: The BREAK variable XXXX is not one of the GROUP or ORDER variables.

PROC REPORT does not have the ability to have multiple summary rows on the same variable or location. You’ll receive this error message if you have used one variable twice on the COLUMN statement (once using an alias), defined it as GROUP or ORDER, and there is a BREAK statement for both the variable and its alias.

Circumvention: Create a new variable in a DATA step that is a copy of the variable and use the new variable on the COLUMN statement instead of an alias.

data class;
 set sashelp.class;
 sex2=sex;
proc report data=class;
 column sex sex2 weight;
 define sex /group;
 define sex2 /group;
 break after sex /summarize;
 break after sex2 /summarize;
run;

#5.  Two different usages for the same variable

proc report data=sashelp.class;
 column age sex name age=age2;
 define age /group;
 define sex /group;
 define age2 /display;
run;

ERROR: XXXX conflicts with earlier use of XXXX.

In some circumstances PROC REPORT will not let you have two different usages for the same variable. In the example above, the variable age cannot be both GROUP and DISPLAY. An alias is most useful when you have an analysis variable that you want multiple statistics for, such as mean, min, or max. However, you can use an alias on any type of variable, but you do have to be careful about the usage issue.

Circumvention: Create a new variable in a DATA step that is a copy of the variable. This way the new variable contains the same information but can be used in any way you choose in the PROC REPORT step.

data class;
 set sashelp.class;
 age2=age;
proc report data=class;
 column age sex name age2;
 define age /group;
 define sex /group;
 define age2 /display;
run;

#6.  No format specified for LINE statement variable

proc report data=sashelp.class;
 column sex name age;
 define sex /group noprint;
 compute before sex;
   line 'this is for gender group ' sex;
 endcomp;
run;

ERROR: XXXX must use a character format.

This error normally occurs when a character variable is used on a LINE statement, and no format is specified after it. On a LINE statement you must specify a format for each item (variable).

Circumvention: Add an appropriate format after the variable on the LINE statement.

proc report data=sashelp.class;
 column sex name age;
 define sex /group noprint;
 compute before sex;
   line 'this is for gender group ' sex $1.;
 endcomp;
run;

See the REPORT procedure documentation for details on each of these statements.
tags: Problem Solvers, PROC REPORT, SAS Programmers