BookmarkSubscribeRSS Feed
0 Likes

Add an option /RETAIN to the SET statement which would command SAS not to clear the program data vector (PDV) prior to each dataset read. 

 

Example:

data Whole:
  set Left Right Center /Retain;
    BY v1;
run;

"Left" dataset:

v1   v4
A998 Q

"Right "dataset:

v1   v2
A998 06/01/18 B027 05/21/18 E001 03/31/18 F221 11/01/17 C379 10/07/17 G693 06/19/18

"Center" dataset:

v1   v3
A998 Z A998 Y A998 X A998 W B027 V C379 U D032 T

The result with the proposed /RETAIN option.  The bolded values are "retained" from the PDV unchanged from the prior observation:

v1   v4 v2       v3
A998 Q . A998 Q 06/01/18 A998 Q 06/01/18 Z A998 Q 06/01/18 Y A998 Q 06/01/18 X A998 Q 06/01/18 W B027 Q 05/21/18 W B027 Q 05/21/18 V C379 Q 10/07/17 V
C379 Q 10/07/17 U D032 Q 10/07/17 T E001 Q 03/31/18 T
F221 Q 11/01/17 T
G693 Q 06/19/18 T

The result without the proposed /RETAIN option:

v1   v4 v2       v3
A998 Q . A998 06/01/18 A998 . Z A998 . Y A998 . X A998 . W B027 05/21/18 B027 . V C379 10/07/17 C379 . U D032 . T E001 03/31/18 F221 11/01/17 G693 06/19/18

 

 

2 Comments
PhilC
Rhodochrosite | Level 12

Another way to put it, all variables created by this SET statement using this proposed /RETAIN option would be treated as variables created within the data step and as if a RETAIN statement were applied to each variable.

PhilC
Rhodochrosite | Level 12

I would use this to perform date matching for data that needed to match data giving respect to the chronological ordering of timestamps.