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=p0+αρ, resulting in an effective cosmological constant ρΛ=-p0/(1+α). 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(ρ), 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, α and ΩΛ, using data from a suite of different cosmological observations, and perform a comparison with the standard Λ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 ΛCDM, with best-fit values α=0.01±0.02 and ΩΛ=0.70±0.04 (95% confidence intervals). The standard model (best-fit ΩΛ=0.71±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 ΛCDM. For the latter, the best-fit values are ΩK=-0.02-0.02+0.01 and ΩΛ=0.71±0.04, i.e. a closed model is preferred. A phantom UDM with affine EoS is ruled out well beyond 3σ.