First-principles electronic structure and positron state calculations for transition metal carbides and nitrides are performed. Perfect NaC1-structures as well as structures with metal or carbonJnitrogen vacancies are considered. The positron affinities and lifetimes are determined. The trends are discussed and the results are compared with recent positron lifetime measurements for group IV and V refractory metal carbides and in hexagonal WC. The present analysis indicates, contradictory to an earlier interpretation, that positrons are trapped and annihilated both at carbon and metal vacancies. The concentration of metal vacancies seen by positrons is probably very low, below the sensitivity limit of the other experimental methods. Experimental data for WC may be well understood if a Bloch-like state in the lattice with carbon va.cancies is employed as an initial positron state in the trapping model.