I see documentation out there in the SAS site called "CASL Reference" : SAS Help Center: DO OVER Statement. That website displays "SAS 9.4/Viya 3.4" on the top left of my web browser. I am weary of using that to support the argument that DO OVER is documented, since I still do not see "Do Over" in the documentation at SAS Help Center: Dictionary of SAS DATA Step Statements.
Anyone know the status?
I could never find it in the current documentation, so yes, it's undocumented.
"Do Over" was pretty much deprecated in SAS 6, I believe. SAS tries to make sure that prior code will run so no errors and will work in existing code. Not documenting a bit of code is one way of saying "it works now but you never know when it might stop and probably should not be using it."
The biggest weakness with the "Do Over", at least in my opinion, what that you really can't use two or more arrays in the same loop.
Example: The following code will run, not doing much of anything serious:
data junk; array x x1-x5; array z {5}; do over x; x=sum(x,1); /* z=sum(z,1);*/ end; run;
If you un-comment the z= sum() bit however you will get illegal array reference errors. Or anything using Z in that loop.
Another limitation:
In old SAS versions -
DO OVER was defined as implicit do loop
The indexed DO ( as do i=1 to ...) was defined as explicit do loop
and it generated an error if the data step used both methods.
@Shmuel wrote:
Another limitation:
In old SAS versions -
DO OVER was defined as implicit do loop
The indexed DO ( as do i=1 to ...) was defined as explicit do loop
and it generated an error if the data step used both methods.
I thought I remembered the implicit/explicit convention but since it isn't the current documentation searching for "implicit" didn't come up with arrays.
I remember learning the "Do over" in SAS 5.18 and thought "cool, no need to keep track of indexes". And then immediately ran into the "can't use two arrays in the same loop", not so cool. Just easier not to use it.
Interesting 🙂
The also have removed the documentation that you don't have to waste time type the dimension (or even using * as a place holder) when defining the array.
But there is no limitation on use multiple arrays.
You just cannot mix implicit and explicit array indexing for the same array.
If you don't tell SAS what variable to use for the implicit index then it will use _I_ .
So here is an example where arrays A and C are indexed implicitly and B is indexed explicitly.
data junk;
array A A1-A5 (5*1);
array B B1-B5 (5*2);
array C C1-C5 ;
do over a;
c=a+b[_i_];
end;
put (_all_) (=);
run;
yeah, that's right. thanks @Tom. I was trying to recall the index, _i_, earlier.
Re: "DO OVER" is Undocumented for SAS 9.4, Right?
Perhaps IT IS documented for SAS 9.4 under CAS/CASL. So it should be said that "it is not documented for 'base SAS programming' "? I think I'm right. Please correct me if you disagree.
Thanks for all the insightful responses so far.
Two different things. One (documented) is a statement in PROC CAS, the other (undocumented) a DATA step statement.
I like the implicit array and the Do Over syntax. First of all, I like the clean look of it. Also, the syntax makes good sense to me logically: Do this operation over that range of variables. If the syntax does not make sense, I don't know why they replicated it with the Do_Over Hash Object Method (Available since 9.4).
Using multipe Do Over loops though, you have to think about the index variable (_I_ by default).
For example, this fails.
data _null_;
array a a1-a2 (1:2);
array b b1-b3 (1:3);
do over a;
do over b;
put a= b=;
end;
end;
run;
This works
data _null_;
array a(i) a1-a2 (1:2);
array b(j) b1-b3 (1:3);
do over a;
do over b;
put a= b=;
end;
end;
run;
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 25. Read more here about why you should contribute and what is in it for you!
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.