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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 405 views
  • 2 likes
  • 2 in conversation