VBA
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
SAS
User-defined format by PROC FORMAT is the best way for quick replacements.
proc format;
value $sex
'F' = 'Female'
'M' = 'Male'
;
run;
data want;
set sashelp.class;
format sex $sex.;
run;
Conclusion
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.
No comments:
Post a Comment