Sas Delete and Return Statements

I'm looking at someone else's code and trying to determine if:

if x = y then do;
    delete;
    return;
end;

is equivalent to:

if x = y then do;
    delete;
end;

From the documentation on DELETE:

When DELETE executes, the current observation is not written to a data set, and SAS returns immediately to the beginning of the DATA step for the next iteration.

Which leads me to believe the 'return' statement in the first example is not executed?

1

1 Answer

May as well test, rather than guess.

  1. Create a data set with x/y values, one that will meet the condition and one that will not.
  2. Run the data step and add PUT statement so you can trace the log

From the log you see that nothing after the DELETE is executed, so you can confirm that RETURN is not executed and is redundant.

FYI - one thing to consider - has this behaviour changed over time or has the code changed where perhaps this was once valid? Usually that's the case.

data have;
input x y;
cards;
1 2
1 1
;;;;
run;


data demo;
set have;
if x = y then do;
    put "Record Deleted 1";
    delete;
    put "Record Deleted 2";
    return;
    
    put "Record Deleted 3";
    
end;
else put "Record Retained";

run;

Log:

 78         data demo;
 79         set have;
 80         if x = y then do;
 81             put "Record Deleted 1";
 82             delete;
 83             put "Record Deleted 2";
 84             return;
 85         
 86             put "Record Deleted 3";
 87         
 88         end;
 89         else put "Record Retained";
 90         
 91         run;
 
 Record Retained
 Record Deleted 1
 NOTE: There were 2 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.DEMO has 1 observations and 2 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              798.71k
       OS Memory           24232.00k
       Timestamp           10/18/2021 10:25:05 PM
       Step Count                        39  Switch Count  2
       Page Faults                       0
       Page Reclaims                     135
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest