Reputation: 3682
I am unsure if this code will run without a warning or error. I have set the key
option with the UNIQUE
modifier.
What happens in set
line?
data One(keep= f1 f2);
attrib f2 length = $4;
set Two key = f3 / unique; /* Unexpected behaviour? */
if (f1=0) then do;
f2 = 'Zero';
output;
end;
run;
Upvotes: 0
Views: 1294
Reputation: 7602
The KEY= option is used against a lookup dataset that has been indexed, the values of which are looked up in a second dataset. The data step therefore requires 2 set statements. In your code there is no dataset to lookup the values from 'Two', which results in an infinite loop with all variables having a missing value. If you added the 'Two' dataset in a separate SET statement, then it will just return a copy of it (without the f3 variable and with the transformation you put in). You obviously wouldn't ever want to do this, I'm just suggesting it to make the code work.
There are plenty of examples online on how to perform an index key merge, it is an efficient technique if you are looking up a small number of values in a large dataset.
Upvotes: 4
Reputation: 9618
Not sure what you are asking. It is syntactically correct as long as your data set TWO has an index named F3. That index might be a composite index (multiple variables) or a single index on a variable named F3. And the variable F1 might be in the data set TWO, but if not it will be missing.
Upvotes: 1