Monday, March 30, 2009

Wonderful paper: Don't Be a SAS Dinosaur

As a SAS programmer, I strongly recommend that you should read this paper.
Warren Repole has summarized many SAS tips systematically.

For more information, please read http://www.repole.com/dinosaur/.

Monday, March 16, 2009

WOW, FCMP is comming

In the past, we have to use macro or format trick for user defined function.
The macro implementation is lengthy and error-prone.
Furthermore, due to inefficiency of communication between macro facility and others, the performance is bad.

With the release of SAS V92, we can take advantage of PROC FCMP.
I believe many SAS professionals have been expecting this for a long time.

It is definitely the most useful upgrade in BASE for SAS 9.2.

LOCF by using only PROC SORT

LOCF is short for Last Observation Carried Forward. It is a common method in longitudinal studies. And there are many ways to handle this. Here is one tip of using NODUPKEY option.

/* Classical way */
proc sort data=inds;
by subjid DESCENDING visitnum;
run;
data locf;
set inds (where=(visitnum <=3));
by subjid visitnum;

retain base;
if first.subjid then base=.;
if not missing(value) then base=value;
if last.subjid;
run;

/* Use NODUPKEY option in PROC SORT. */
proc sort data=inds;
by subjid DESCENDING visitnum;
run;
proc sort data=inds(where=(visitnum <=3 and not missing(value))) out=locf NODUPKEY;
by subjid;
run;

Thursday, March 12, 2009

Useful keyboard macros

As a programmer, I always use Ultraedit and VI as editor. So I am familiar with the keyboard shortcut in Ultraedit and VI. After immigrating some useful shortcuts into SAS enhanced editor using keyboard macros, my coding efficiency has been improved dramatically.
It should be noted to avoid shortcut conflict with old ones before assign new shortcut key.

Here are two useful keyboard macros:
Mark matching DO/END:
* Move cursor to matching DO/END keyword
* Mark the current line
* Move cursor to matching DO/END keyword
* Mark the current line
* Move cursor to matching DO/END keyword

Unmark matching DO/END:
* Move cursor to matching DO/END keyword
* Unmark the current line
* Move cursor to matching DO/END keyword
* Unmark the current line
* Move cursor to matching DO/END keyword

Below is a paper for keyboard macros in SAS enhanced editor.
http://www.sascommunity.org/wiki/Tip:_Useful_Enhanced_Editor_macros

Sunday, March 1, 2009

macro invocation to CALL routines

In macro world, we have to use %sysfunc to call SAS functions.
Accordingly, %syscall is the door to SAS CALL routines.

%let pattern = %sysfunc(prxparse(/test/i));
%let rc = %sysfunc(prxmatch(&pattern, %str(this is a test)));
%syscall prxfree(pattern);