Don't Be a SAS® Dinosaur: Modernizing Programs with Base SAS 9.2 Enhancements Warren Repole Jr., SAS Institute Inc.
ABSTRACT
New features of the SAS® programming language often permit the replacement of complex algorithms and clunky workarounds with more elegant code. Some enhancements support the creation of more efficient solutions. Whether you are a SAS programmer with many years of experience or a novice user who is responsible for maintaining legacy programs, implementing updated approaches can allow you to streamline your SAS applications, expedite the development and debugging process, and minimize future maintenance of the code.
INTRODUCTION
This paper covers a selection of enhancements implemented in SAS 9.2, including new features of Base SAS procedures, the DATA step, functions, formats, and the macro language. Each enhancement is paired with an alternative technique available prior to SAS 9.2. This allows for comparison of older and newer approaches. The primary motivation for exploiting SAS 9.2 enhancements is the ability to create robust yet easy-to-maintain SAS programs with less programmer effort. Efficiency gains in terms of machine resources might be achieved, but they are of secondary importance in most examples.
BASE SAS PROCEDURES
PROC PRINT: BLANKLINE= OPTION
Inserting a blank line into PROC PRINT output after every n observations could enhance readability, but this was difficult to accomplish prior to SAS 9.2. Observations with missing values were inserted, the MISSING= system option was switched to a blank (then reset to its default value afterward), and the NOOBS option was required. In SAS 9.2 producing this type of report is simple using the BLANKLINE= option in the PROC PRINT statement. data class_blanks(drop=i); set sashelp.class; output; if mod(_n_,5)=0; array alln {*} _numeric_ ; array allc {*} _character_ ; do i=1 to dim(alln); alln{i}=.; end; do i=1 to dim(allc); allc{i}=" "; end; output; run; options missing=" "; proc print data=class_blanks noobs ; run; options missing=".";
Figure 1c. Output from Figure 1b program including the Obs column suppressed in Figure 1a program PROC SORT: SORTSEQ= OPTION
Sorting character data that is stored inconsistently in terms of case has been a challenge for many years. Typical solutions involved converting the data to uppercase using the UPCASE function before sorting. In SAS 9.2 the SORTSEQ= value of LINGUISTIC with the collating rule STRENGTH=PRIMARY supports sorting that is not case sensitive. Diacritical differences and punctuation are handled through other STRENGTH= settings. data french; set maps.names; where Territory contains "France"; Territory_Upper=upcase(Territory); run; proc sort data=french; by Territory_Upper Name ; run; proc sort data=maps.names out=french sortseq=linguistic (strength=primary) ; where Territory contains "France"; by Territory Name ; run;
Figure 2a. PROC SORT using uppercase values
Figure 2b. PROC SORT using SORTSEQ=LINGUISTIC option
Collating rules associated with the sorted data are exploited in subsequent BY statements.
TERRITORY Overseas Department of France TERRITORY Overseas Department of France Overseas