Googling is not an option?
Code:
sed -n '/^AAA/wAAA.dat
/^BBB/wBBB.dat' file
Notice that writing doesn't have any side effect (such as, for example, finish this line and fetch the next) so if you have patterns which overlap, you can get the same line written to multiple files (or need to write a slightly more complex script).