You have a good question. Sometimes I am also confused about it. Maybe it is not right, my understandings are:
The %do-end% statements are valid only inside a macro definition, for example
%macro test;
%do year=2011 %to 2013;
%do month=1 %to 12;
%put &year.&month;
%end;
%end;
%mend test;
%test
%macro print;
%do year=1980 %to 1994;
proc print data=sashelp.retail;
where year=&year;
run;
%end;
run;
%mend print;
%print
you could not replace %do-%end with do-end, such as:
%macro test;
do year=2011 to 2013;
do month=1 to 12;
%put &year.&month;
end;
end;
%mend test;
%test
So %do loop could be used everywhere in a macro definition, do loop could be only used in DATA STEP within a macro definition, in some conditions it is allowed to use either like your examples, in some conditions like follows, %do-%end could not be replaced by do-end, so the best way is to use %do-%end in macro program.
data class;
set sashelp.class;
run;
%macro make_ind(dsn,cat);
proc sort data=&dsn out=sorted;
by &cat;
run;
data _null_;
set sorted end=eof;
by &cat;
if first.&cat then do;
tot+1;
call symputx("&cat.ind"||compress(tot),compress(&cat));
end;
if eof then call symputx('tot',tot);
run;
data &dsn._ind;
set &dsn;
%do i=1 %to &tot;
if &cat="&&&cat.ind&i" then &&&cat.ind&i =1;
else &&&cat.ind&i =0;
%end;
run;
%mend make_ind;
%make_ind(class,sex)