SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

Macro Do Loop Continue or Leave

Started ‎07-05-2018 by
Modified ‎07-05-2018 by
Views 12,263

This example shows data step and macro examples of the loop exit verbs:

  • continue: skip to 'end;' statement, where iteration happens
  • leave: exit loop
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

Version history
Last update:
‎07-05-2018 05:02 PM
Updated by:
Contributors

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags