A more general-purpose code logic would be to use IF FIRST.usubjid THEN DO; END; logic to test initialize a "temporary" SAS variable to the desired no-match condition, and use a RETAIN to keep track of this variable, and if the desired "match" condition is encountered for the "test" variable, set the "temporary" variable to a given value. The, use the IF LAST.usubjid THEN DO; END; logic to reset RESULT to the temporary variable and do an OUTPUT.
This logic flow does not require a particular sort-sequence or "match" value order condition to work properly. The key here is using the RETAIN statement to track a temporary variable in the DATA step (remember to either DROP this var or specify a KEEP statement).
Scott Barry
SBBWorks, Inc.