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.
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.
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;
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
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
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
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;
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
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.
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.