BookmarkSubscribeRSS Feed
PhilC
Rhodochrosite | Level 12

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?

11 REPLIES 11
PaigeMiller
Diamond | Level 26

I could never find it in the current documentation, so yes, it's undocumented.

--
Paige Miller
Reeza
Super User
DO OVER was deprecated in SAS V7.

It's still supported for backwards compatibility, I usually don't recommend using it in production code but some others on here actively disagree with that stance.
ballardw
Super User

"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.

Shmuel
Garnet | Level 18

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.

ballardw
Super User

@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.

Tom
Super User Tom
Super User

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;

 

PhilC
Rhodochrosite | Level 12

yeah, that's right. thanks @Tom.  I was trying to recall the index, _i_, earlier.

PhilC
Rhodochrosite | Level 12

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.

PeterClemmensen
Tourmaline | Level 20

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;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 11 replies
  • 1591 views
  • 13 likes
  • 8 in conversation