We study half-BPS surface operators in supersymmetric gauge theories in four and five dimensions following two different approaches. In the first approach we analyze the chiral ring equations for certain quiver theories in two and three dimensions, coupled respectively to four- and five-dimensional gauge theories. The chiral ring equations, which arise from extremizing a twisted chiral superpotential, are solved as power series in the infrared scales of the quiver theories. In the second approach we use equivariant localization and obtain the twisted chiral superpotential as a function of the Coulomb moduli of the four- and five-dimensional gauge theories, and find a perfect match with the results obtained from the chiral ring equations. In the five-dimensional case this match is achieved after solving a number of subtleties in the localization formulas which amounts to choosing a particular residue prescription in the integrals that yield the Nekrasov-like partition functions for ramified instantons. We also comment on the necessity of including Chern-Simons terms in order to match the superpotentials obtained from dual quiver descriptions of a given surface operator.