BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I have a program shown below.  An error message was shown in the log window.   Please help me to fix it.  Thanks.

 

%Macro format_Repeater;

	data Repeater_Rochester_a;
		set Repeater_Rochester;

	%do k = 1 %to 5;
	 		CaseID_&k. = compress(CaseID_&k., "_-");
	%end;
   
		put CaseID_&k.;
	run;
	%end;

%mend;
%format_Repeater;

The error message is list below.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You have two %END statements and only one %DO statement.  And neither is in the right place.

If you keep the first one then you will reference the macro variable K after the end of he %DO loop. In that case its value will be 6.

If you keep the second one then you have included the RUN statement into the %DO loop and the statements generated by K=2 to 5 will be outside of the data step.

View solution in original post

6 REPLIES 6
Reeza
Super User
You forgot the error message, but it looks like you're mixing macro and array logic. Is there a specific reason to not stick with arrays?
ybz12003
Rhodochrosite | Level 12

I am not sure what is going on, somehow I couldn't copy the error text here.

 

ybz12003
Rhodochrosite | Level 12

Error:  There is no matching %DO statement for the %end.  The statement will be ignored.

ybz12003
Rhodochrosite | Level 12

Never mind.  I found out the issue.  thank.

Reeza
Super User
Duplicate %end? 🙂
Tom
Super User Tom
Super User

You have two %END statements and only one %DO statement.  And neither is in the right place.

If you keep the first one then you will reference the macro variable K after the end of he %DO loop. In that case its value will be 6.

If you keep the second one then you have included the RUN statement into the %DO loop and the statements generated by K=2 to 5 will be outside of the data step.

hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1364 views
  • 0 likes
  • 3 in conversation