We investigate the influence of diffusion and mass loss on the chemical composition in subdwarf B stars in the range 25000 K [less-than or equal to] Teff [less-than or equal to] 35000 K, 5.5 [less-than or equal to] log g [less-than or equal to] 6.0. Within the outer hydrogen-rich envelope characterized by mass less than or equal 10-2 M for the elements H, He, C, N and O the equations of continuity, the momentum equations and the equation of radiative transfer are solved simultaneously. For various mass loss rates the time evolution of the chemical composition is predicted within time scales of approximately equals 108 yr, which correspond to the typical lifetimes of the sdB's near the Extended Horizontal Branch. According to the results weak winds with M approximately equals 10-13 M [dot in circle] /yr may explain the typical helium deficiencies by more than one order of magnitude in the atmospheres of these stars. Winds with 10-14 M [dot in circle] /yr less than or equal M less than or equal 10-13 M [dot in circle] /yr may lead to strong deficiencies as well as to enrichments of the CNO elements. The composition in the outer envelope changes in time scales similar to the typical lifetimes of the sdB's. From estimates of the radiative acceleration in the wind region, which make the existence of weak winds plausible, and from a comparison with the case of hot white dwarfs we suggest that the abundance anomalies observed in sdB stars are related to the combined effects of diffusion and mass loss.