The log told you what was wrong twice, MIssing ')' and Expecting a ) in red.
Add an extra bracket.
Obviously without your data I can't test the code.
@sasstatstudent wrote:
Thanks for the tip. I copied and pasted your edit onto my code. Unfortunately it didn't work, as it gave me the Errors shown below (In the meantime, I'll look at the webpages you linked in your reply):
... View more