(10) باب الصَّوْمِ لِمَنْ خَافَ عَلَى نَفْسِهِ الْعُزْبَةَ
Narrated 'Alqama:
While I was walking with `Abdullah he said, "We were in the company of the Prophet (ﷺ) and he said, 'He who can afford to marry should marry, because it will help him refrain from looking at other women, and save his private parts from committing illegal sexual relation; and he who cannot afford to marry is advised to fast, as fasting will diminish his sexual power."
Reference: Sahih al-Bukhari 1905
In-book reference: Book 30, Hadith 15
USC-MSA web (English) reference(deprecated numbering scheme): Vol. 3, Book 31, Hadith 129