When you use last.apple, SAS assumes that your data is sorted by APPLE, and so the last record of each value of APPLE will be output. In your trivial example, there is only one record for each value of APPLE, this one record for each value of APPLE is also the last record for each value of APPLE, and so this record is output.
If we modify the data
data test1;
input apple lemon;
datalines;
4 3
4 7
7 12
7 22
7 80
22 500
;
data fruit;
set test1;
by apple lemon;
if last.apple then output;
run;
You can see now that there are multiple records with each value of APPLE, and the last record of each value of APPLE is output.
--
Paige Miller