The Prophet Muhammad (peace be upon him) once offered prayer while carrying his granddaughter on his shoulder. “The (Prophet) led (the people) in prayer while she was on his shoulder. When he bowed he put her down and picked her up when he got up. He kept on doing so until he finished his prayer.”
Sunan of Abu-Dawood, Hadith 353
One commentator wrote: "The purpose behind the action of the Prophet of carrying (his granddaughter) in the prayer was to set an example before the Arabs who considered having daughters and carrying them around as something bad or shameful. The Prophet…acted differently from them, and carried a girl on his neck in the prayer, and making something clear by example is much more effective than a mere precept."
Fiqh-us-Sunnah, Volume 2, Number 84