Monday, October 1, 2012

SAS and VBA (5) : replace values quickly

SAS and VBA both have their unique and quick ways to replace values in one or multiple columns.

VBA has a wonderful function Replace for several columns or regions, where the changes are likely to be happened.
Sub Replace()
   With Columns("B")
      .Replace "F", "Female"
      .Replace "M", "Male"
   End With
End Sub

User-defined format by PROC FORMAT is the best way for quick replacements.

proc format;
   value $sex
      'F' = 'Female'
      'M' = 'Male'

data want;
   set sashelp.class;
   format sex $sex.;

For some data management operations such as string/number replacement, it is better way to use the languages' built-in features, instead of the loops and condition statements.

Good math, bad engineering

As a formal statistician and a current engineer, I feel that a successful engineering project may require both the mathematician’s abilit...