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

Do statement needs a semicolon as below. 

 

DO; 

SAS satement ; 

END;

 

 

But recently, I happend to omit the semicolon next to DO statement and it still works and generated the same results as with semicolon. Does that mean that I don't have to worry about the semicolon for DO statement?

 

Thank you in advance for your help. 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Well, I had a chance to think about this on the ride home.  If that's the question, I think you're right.  The closest I could imagine was this:

 

data testing;

before = time();

do i=1 to 10000000;

   do after = time();

   end;

end;

diff = after - before;

run;

 

Compare that with the added semicolon:

 

data testing2;

before = time();

do i=1 to 10000000;

   do;

   after = time();

   end;

end;

diff = after - before;

run;

 

Now if for some reason the programs differ in their execution time, DIFF would change.  Even so, that's a lot of imagination with zero practicality.

View solution in original post

8 REPLIES 8
Reeza
Super User

 

It depends. What kind of code did you have after DO?

 

You can include certain statements after a DO that control the loop. 

And others will generate an error. 

 

In fact, I'd say it's unusual to see just a DO, it would be something like

 

if x=1 then do;

 

or 

 

Do i=1, 2, 3 6;

 

http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#p1cydk5fq0u4bfn...

 

 

 

minitt01
Fluorite | Level 6

Thank you for your opinion. 

 

Yes, it was in IF/THEN statement. I was expecting an error message but there was not. That's why I was confused. 

 

Let me try it with some other data and see how it works. 

 

Thank you again, 

MJ

mkeintz
PROC Star

I guess what your are really asking is:  SAS appears to not object in certain cases when you forget to terminate the DO statement with a semi-colon.  And in those cases, if SAS doesn't object, can you be sure the result will be the same as it would be with the semi-colon in place?

 

I don't know, but I wouldn't trust it.

 

At the moment, I can't think of a counterexample. 

 

 

For instance these two support the "no difference" conjecture, but that's not proof:

  do;

   x=1;

   y=3*x;

  end;

 

and

 

  do

   x=1;

   y=3*x;

  end;

 

regards,

Mark

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
minitt01
Fluorite | Level 6

Thank you for your attention on this topic. 

 

Yes, I was confused cuz it didn't give me any error message and generated the same result.

 

I don't know why this still works.. need to search more. 

 

Thank you again, 

MJ

Astounding
PROC Star

The key to removing the semicolon is that the result has to create a valid DO statement.  So if the next statement is:

 

name='Fred';

 

That works, because this would be a valid DO loop:

 

do name='Fred';

 

It both sets NAME to "Fred" and performs any additional statements within the loop.

 

But if the next statement wouldn't form a valid DO statement, you will get an error.  A few examples where omitting the semicolon gives you an error because the resulting DO statement is no longer correct syntax:

 

if name='Fred' then salary='High';

 

substr(name, 4,1)='t';

 

select (name);

 

array names {1} name;

 

retain total 0;

mkeintz
PROC Star

Yes, but in your example ("do  if ...."), SAS would send an error message, thereby protecting the programmer from the oversight. 

 

I think the OP's issue is: if there's no such error message, can there ever be a difference in results attributable to the missing semi-colon?

 

M K

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

Well, I had a chance to think about this on the ride home.  If that's the question, I think you're right.  The closest I could imagine was this:

 

data testing;

before = time();

do i=1 to 10000000;

   do after = time();

   end;

end;

diff = after - before;

run;

 

Compare that with the added semicolon:

 

data testing2;

before = time();

do i=1 to 10000000;

   do;

   after = time();

   end;

end;

diff = after - before;

run;

 

Now if for some reason the programs differ in their execution time, DIFF would change.  Even so, that's a lot of imagination with zero practicality.

minitt01
Fluorite | Level 6

Thank you for your opinion. 

 

Yes I expected an error message but it runs without error message. 

I thought that SAS code is very sensitive on Semicolon and operators. 

I need to search little more detail about this. 

 

Thank you again, 

MJ

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 8 replies
  • 2278 views
  • 2 likes
  • 4 in conversation