Topic
Avoiding an implicit retain while merging two data sets in a data step
Keywords
*data step #merge
Data
data one; subject=1; test='A'; x=1; output; subject=1; test='B'; x=2; output; subject=1; test='C'; x=3; output; subject=2; test='A'; x=1; output; run;
data two; subject=1; y=100; output; subject=2; y=200; output; run;
Dataset |
Dataset |
Program
data demo; merge one two; by subject; if test='B' then y=999; run;
Dataset |
Dataset |
Dataset |
The datasets one
and two
are merged by subject
. The value of y
is then updated when test='B'
.
But When test='C'
, the value of y
does not remain 100; It is also modified.
Task
Update the program to get the following result:
Dataset |
Dataset |
Dataset |
Possible Solution
data demo; merge one two; by subject; run; data demo; set demo; if test='B' then y=999; run;