Sunday, May 17, 2009

How to avoid "retain" observations in Match-Merging

There are two merging techniques: One-to-One Merging and Match-Merging.
Match-Merging is the most popular operation in SAS DATA step programming.
The reason is that Match-Merging always “retain” last observation until new one is read into PDV.
(Note that One-to-One merging is not.)

However, sometimes we need not retain last observation.
Since SAS do not provide option to control it, we have to initialize PDV manually every time.

Here is the code:

OUTPUT; * save PDV to dataset;
ARRAY CHAR _CHARACTER_ ;
ARRAY NUM _NUMERIC_ ;
DO OVER CHAR ; CHAR = '' ; END ;
DO OVER NUM ; NUM = . ; END ;


or

*For SAS 9.1 and later;
OUTPUT;
CALL MISSING(OF _ALL_);

No comments: