We consider the hypothesis that dark energy and dark matter are the two faces of a single dark component, a unified dark matter (UDM) that we assume can be modeled by the affine equation of state (EoS) $P={p}_{0}+\ensuremath{\alpha}\ensuremath{\rho}$, resulting in an effective cosmological constant ${\ensuremath{\rho}}_{\ensuremath{\Lambda}}=\ensuremath{-}{p}_{0}/(1+\ensuremath{\alpha})$. The affine EoS arises from the simple assumption that the speed of sound is constant; it may be seen as an approximation to an unknown barotropic EoS $P=P(\ensuremath{\rho})$, and may as well represent the tracking solution for the dynamics of a scalar field with appropriate potential. Furthermore, in principle the affine EoS allows the UDM to be phantom. We constrain the parameters of the model, $\ensuremath{\alpha}$ and ${\ensuremath{\Omega}}_{\ensuremath{\Lambda}}$, using data from a suite of different cosmological observations, and perform a comparison with the standard $\ensuremath{\Lambda}\mathrm{CDM}$ model, containing both cold dark matter and a cosmological constant. First considering a flat cosmology, we find that the UDM model with affine EoS fits the joint observations very well, better than $\ensuremath{\Lambda}\mathrm{CDM}$, with best-fit values $\ensuremath{\alpha}=0.01\ifmmode\pm\else\textpm\fi{}0.02$ and ${\ensuremath{\Omega}}_{\ensuremath{\Lambda}}=0.70\ifmmode\pm\else\textpm\fi{}0.04$ (95% confidence intervals). The standard model (best-fit ${\ensuremath{\Omega}}_{\ensuremath{\Lambda}}=0.71\ifmmode\pm\else\textpm\fi{}0.04$), having one less parameter, is preferred by a Bayesian model comparison. However, the affine EoS is at least as good as the standard model if a flat curvature is not assumed as a prior for $\ensuremath{\Lambda}\mathrm{CDM}$. For the latter, the best-fit values are ${\ensuremath{\Omega}}_{K}=\ensuremath{-}{0.02}_{\ensuremath{-}0.02}^{+0.01}$ and ${\ensuremath{\Omega}}_{\ensuremath{\Lambda}}=0.71\ifmmode\pm\else\textpm\fi{}0.04$, i.e. a closed model is preferred. A phantom UDM with affine EoS is ruled out well beyond $3\ensuremath{\sigma}$.