BookmarkSubscribeRSS Feed
simmwa
Fluorite | Level 6

The following "do I=1 to 2" code will fail after Auto Indenter is run using CTRL-I on SAS EG. The error only occurs when the do loop is part of an "else if" condition.

 

data have;
input col1$ col2;
datalines;
a 0123
b 345
b 456
d 711189
x    
u 3033
w 1234567890
run;

data want1;
set have;
if col1 = 'b' then do;
	new = cats('b', col2); output; end;
else if col1 = 'd' then do i= 1 to 2;
	if i = 1 then do; new = cats('d', col2); output; end;
	if i = 2 then do; new = cats('db', col2); output; end;
	end;
run;

data want2;
set have;
if col1 = 'b' then do i= 1 to 2;
	if i = 1 then do; new = cats('b', col2); output; end;
	if i = 2 then do; new = cats('bc', col2); output; end;
	end;
else if col1 = 'd' then do;
	new = cats('d', col2); output; end;
run;

After CRTL-I there is an extra semi colon between the do and I = 1 to 2

data want1;
	set have;

	if col1 = 'b' then
		do;
			new = cats('b', col2);
			output;
		end;
	else if col1 = 'd' then
		do;
			i= 1 to 2;

			if i = 1 then
				do;
					new = cats('d', col2);
					output;
				end;

			if i = 2 then
				do;
					new = cats('db', col2);
					output;
				end;
		end;
run;

Is there some Indenter option I have set incorrectly ?

2 REPLIES 2
Patrick
Opal | Level 21

Using SAS EG8.2 I can replicate what you describe. It looks like formatting code adds a semicolon to the code....

Looks like a bug to me. Can you please raise this with SAS Technical Support

 

Before formatting the code

Capture.JPG

 

After formatting the code

Capture.JPG

simmwa
Fluorite | Level 6

SAS Technical support were able to replicate and are now working on a fix.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 2 replies
  • 482 views
  • 2 likes
  • 2 in conversation