This example shows data step and macro examples of the loop exit verbs:
DATA _Null_; do I = 1 to 3; put I= 'pre-test'; if I le 2 then continue; put I= 'post test'; end; put 'done continue: ' I= ; do J = 1 to 3; put J= 'pre-test'; if J gt 2 then leave; put J= 'post test'; end; put 'done leave: ' J= ; stop; run; %Macro Do_Tests(i=,j=); %do I = 1 %to 3; %put I=&I. pre-test; %if &I le 2 %then %goto continue; %put I=&I. post test; %continue: %end; %put done continue: I=&I. ; %do J = 1 %to 3; %put J=&J. pre-test; %if &J. gt 2 %then %goto leave; %put J=&J. post test; %end; %leave: %put done leave: J=&J. ; %Mend; %Do_Tests
This was originally posted by Ron Fehd on sasCommunity.org
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.