diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index b1f77541b48f1786399b5ef6c30704a0b5ed67ba..a8194d86b634685172fd28727e704ba485e40f07 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -389,6 +389,15 @@ ExprNode::isConstant() const
   return symbs_lags.empty();
 }
 
+bool
+ExprNode::hasExogenous() const
+{
+  set<pair<int, int>> symbs_lags;
+  collectDynamicVariables(SymbolType::exogenous, symbs_lags);
+  collectDynamicVariables(SymbolType::exogenousDet, symbs_lags);
+  return !symbs_lags.empty();
+}
+
 
 NumConstNode::NumConstNode(DataTree &datatree_arg, int idx_arg, int id_arg) :
   ExprNode{datatree_arg, idx_arg},
diff --git a/src/ExprNode.hh b/src/ExprNode.hh
index 766f00cfae873118b122ff38e5566f6d8f9901bd..85d4ce79bc0a98002aad3ad43a2cc5ec2c58aa2e 100644
--- a/src/ExprNode.hh
+++ b/src/ExprNode.hh
@@ -707,6 +707,9 @@ public:
   /* Returns true if the expression contains no endogenous, no exogenous and no
      exogenous deterministic */
   bool isConstant() const;
+
+  // Returns true if the expression contains an exogenous or an exogenous deterministic
+  bool hasExogenous() const;
 };
 
 //! Object used to compare two nodes (using their indexes)
diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 60d05907a76439b0a3d4dbb6ffaf1c52bdb7655b..1059e81c46d1832934c102d6b7d8e6c9ecae850e 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -2796,13 +2796,8 @@ expr_t
 ParsingDriver::add_steady_state(expr_t arg1)
 {
   // Forbid exogenous variables, see dynare#825
-  set<int> r;
-  arg1->collectVariables(SymbolType::exogenous, r);
-  if (r.size() > 0)
+  if (arg1->hasExogenous())
     error("Exogenous variables are not allowed in the context of the STEADY_STATE() operator.");
-  arg1->collectVariables(SymbolType::exogenousDet, r);
-  if (r.size() > 0)
-    error("Exogenous deterministic variables are not allowed in the context of the STEADY_STATE() operator.");
 
   return data_tree->AddSteadyState(arg1);
 }
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index e8cccd150363f50bfffe9f3b65a94d3f0dae71ec..daf54426fcbe0506da8b5337641b883168a2e289 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -1829,13 +1829,8 @@ bool
 StaticModel::exoPresentInEqs() const
 {
   for (auto equation : equations)
-    {
-      set<int> result;
-      equation->collectVariables(SymbolType::exogenous, result);
-      equation->collectVariables(SymbolType::exogenousDet, result);
-      if (!result.empty())
-        return true;
-    }
+    if (equation->hasExogenous())
+      return true;
   return false;
 }