Actually sex has been assigned shortly after birth. Approximately 1% of babies are born with external sex organs that make it difficult to know their sex. Around 1900 Dr. Hugh Young of Johns Hopkins Hospital had a clinic for those babies. He did internal and external exams and made the decision that determined the way in which the baby would be raised. He assigned a sex with the ‘best’ information they had then.
Isn’t there DNA testing available now to find out immediately what will happen when such babies reach puberty?