Attempts at coding economy can lead you astray.
In the following why does the loop continue past 'g' ?
data _null_;
length message $200;
do s='a','b','d','g','x','y','z' until (not missing(message));
message = ifc (s='g','Hey, s reached ' || s,'');
msg_is_not_missing = not missing(message);
put s= msg_is_not_missing= message=;
end;
run;
Which logs
s=a msg_is_not_missing=0 message=
s=b msg_is_not_missing=0 message=
s=d msg_is_not_missing=0 message=
s=g msg_is_not_missing=1 message=Hey, s reached g /* why does loop keep going */
s=x msg_is_not_missing=0 message=
s=y msg_is_not_missing=0 message=
s=z msg_is_not_missing=0 message=
Turns out the UNTIL applies only to the specification it is associated with, and DO can have multiple specifications separated by commas.
Reformatting the code so each specification is on its own line makes the reason/rule a little more clear:
do s = 'a' , 'b' , 'd' , 'g' /* no until here */ , 'x' , 'y' , 'z' until (not missing(message)) ;
To escape the loop according to initial expectations you would have to code inside the DO
if not missing (message) then leave;
SAS Help Center: DO Statement: Iterative
... View more