Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question: Exiting a Macro Iteration

Status
Not open for further replies.

Medvedeff

Instructor
Feb 12, 2008
29
US
I posted before about generating unique random values. I have since that time altered my strategy for getting my code to work, though it still doesnt, and I am still looking for a solution.

I am trying to test for equality in two variables in a single dataset. If such an equality exists, for example if variables X and Y both have a value of 3 in the same observation, then I want to exit out of the current iteration and do it over again.


%macro MC(name= ,number= );
%DO n=1 %to &number;
DATA &name&n;
%samp;
%srt;
RUN;

DATA &name&n;
SET &name&n;
LAGRY=LAG(RY);
If RY=LAGRY then skip;
RUN;
skip: n=n-1;
%END;
%mend MC;

Do any of you have a suggestion as to how I can "quit" the current iteration and do it agian?


I have also tried the following:

%macro MC(name= ,number= );
%do %until (count=&n);
DATA &name&n;
%samp;
%srt;
RUN;

DATA &name&n;
SET &name&n;
LAGRY=LAG(RY);
If RY ne LAGRY then COUNT+1
RUN;
%END;
%mend MC;

Any suggestions?
 
Have you tried using a GOTO statement.

Here is a little counting macro, I have since changed it to much simpler code which does the same thing I wanted, but this may work for you.
Essentially it scans a text string &CorVars and increments &NumCorVars by 1, when &CorVars is equal to nothing it exits the %do loop.

Code:
%let NumCorVars=0;
%macro NumOfCorVars;
%do i = 1 %to 50;
	%if %scan(&CorVars, &i) =  %then [COLOR=red]%goto EndOfCorVars;[/color]
	%let NumCorVars = %eval(&NumCorvars +1);
%end;
[COLOR=red]%EndOfCorVars:[/color] 
%mend NumOfCorVars;

HTH,
Petr
 
Yeah, I did try a goto statement a couple different ways but nothing ever worked out exactly as I needed.

I will play around with that code, it looks like I will be able to apply it to what Im doing. Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top