endtat not a variable.  Changed to endat.