Check if variable exists in dbt

I want to implement an SQL query only if the variable exists in dbt. How to do that?