Hi,
There are several problems with your code. Instead of writing the whole thing at once, I would develop it in steps, e.g.:
Code to send one email with "hello".
Code to generate the HTML report you want (PROC TABULATE, or whatever).
Code to send one email with a custom HTML report in the body.
Code to read a dataset and send multiple emails
I would suggest looking at user group papers for examples, this one looked handy:
https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/038-2008.pdf
... View more