## Go to the end of a Macro loop when condition met

Solved
Super Contributor
Posts: 506

# Go to the end of a Macro loop when condition met

Hi Everyone,

I want to end an iteration and move to a new iteration when sample size is less than 5.

Thank you and have a nice weekend.

HHCFX

``````%MACRO test;
%do i=1 %to 100;
%do J=1 %to 100;

LOT OF ANALYSIS;

PROC SQL; SELECT COUNT(*) INTO: SAMPLE_SIZE FROM HAVE;QUIT;

%IF &SAMPLE_SIZE<5 %THEN END THE INNER-LOOP (J)

LOT OF ANALYSIS;

%end;

%end;
%MEND;``````

Accepted Solutions
Solution
‎02-10-2018 10:51 AM
PROC Star
Posts: 1,400

## Re: Go to the end of a Macro loop when condition met

you can use the %GOTO Macro Statement

All Replies
Solution
‎02-10-2018 10:51 AM
PROC Star
Posts: 1,400

## Re: Go to the end of a Macro loop when condition met

you can use the %GOTO Macro Statement

Super Contributor
Posts: 506

## Re: Go to the end of a Macro loop when condition met

[ Edited ]

Thank you.

So it will be like that, right?

``````%MACRO test;
%do i=1 %to %sysfunc(countw(&rr_list));
%do J=1 %to %sysfunc(countw(&sl_list));

LOT OF ANALYSIS;

PROC SQL; SELECT COUNT(*) INTO: SAMPLE_SIZE FROM HAVE;QUIT;

%IF &SAMPLE_SIZE<5 %THEN %GOTO EXIT_EXIT_EXIT;

LOT OF ANALYSIS;

%EXIT_EXIT_EXIT:

%end;

%end;
%MEND;``````

Super User
Posts: 8,214

## Re: Go to the end of a Macro loop when condition met

[ Edited ]

I think you want to replace the semi-colon after

`%EXIT_EXIT_EXIT;`

with a colon (i.e., : )

Art, CEO, AnalystFinder.com

PROC Star
Posts: 1,400

## Re: Go to the end of a Macro loop when condition met

Looks right.

☑ This topic is solved.