Combine SQL query with variable
You can't use double quotes for string literals. Do include a single quote in a string literal, it has to be escaped by doubling them:

query := 'unload (sql) to ''s3_loc/user-data.csv'' iam_role ''role''';


Additionally can't use names of variables from PL/pgSQL in a SQL string. You need to include the content of that variable in the query string you build:

query := 'unload ('||sql||') to '''||s3_loc||'/user-data.csv'' iam_role '''||role||'''';