One way of doing this could be as below, but might not be the most efficient way..
I appreciate your enthusiasm on providing solutions but if do think it is not efficient solution, please refrain from posting it. As Bill mentioned earlier you can use OCCUR operator or simple reporting features in DFSORT to get the desired results.
You don't need 2 passes of data to get the desired results. You Just need the parm NODETAIL. Check this link which explains in detail about NODETAIL
Let's say you have a file containing your e-mail, such that by writing it to a sysout dataset with the appropriate settings, it will be sent (or to any file which will be processed afterwards would also be fine).
Let's say you have a file from which you can select data which requires an e-mail to be sent.
It would then be possible to use a cartesian join with JOINKEYS to output, modified if necessary, e-mails for records matching selection criteria.
So if you have, or can get, e-mails working in that way for you, the rest will be quite simple.
Part - 2 Of the requirement is to generate a alert when the count falls below a tresh hold
So when is Part -3 or Part -4 or Part - n requirement coming up? I always wonder why people show a part of the requirement and when a solution is provided for the specific task they change it or keep on appending requirements to it which makes the solution a moot.
If the count in any particular row falls below a tresh hold I want to generate an alert.
eg: if for row 2 IMSA-6012-Count=5 falls below a pre defined treshold say 3 then I want a alert say email to be triggered.
Let me know if you need any more details.
Take a look at Hailashwin's solution and take the first part of it where he appends a "1" to every record. You need to expand it and sum on it and use OUTFIL Include/Omit and get the desired results.