It is narrated from Anas bin Malik (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "Allah has placed an angel in charge of the womb. He says: O my Lord, a drop of sperm! O my Lord, a clinging clot! O my Lord, a lump of flesh! Then when Allah wills to decree its creation, the angel says: O my Lord, male or female? Wretched or fortunate? What is its provision, and what is the term of its life? All of this is written while it is still in its mother's womb."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب العدد / 15422