DATA Step, Macro, Functions and more

Go to the end of a Macro loop when condition met

Accepted Solution Solved
Reply
Super Contributor
Posts: 506
Accepted Solution

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.

 

Can you please help me with that?

 

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


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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 154 views
  • 1 like
  • 3 in conversation