With an array/do loop you're looping for EACH iteration of the datastep (=for each "line of data", observation). That's something you might want to do if you have a lot of columns.
What you describe is getting information out of passing through the data, line by line. That's something SAS is very good at.
Find below one possibility to get what you want. I used Proc SQL - but it could also be done with Proc Sort and datasteps.
HTH
Patrick
/* create some test data with some duplicate ID 's */
data have;
do i=1 to 1000;
id=ceil(ranuni(1)*500);
output;
end;
run;
/* count per id and write result to variable IDcount */
proc sql;
/* create table want as*/
select l.id, r.IDcount
from have l left join
(select id, count(id) as IDcount from have group by id) r
on l.id=r.id
order by id;
quit;
... View more