Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) said: "When a matter comes before you which must be decided, look at what is in the Book of Allah and judge by it. If you are unable, look at what the Messenger of Allah (peace and blessings be upon him) decided. If you are still unable, look at what the righteous decided. If you are still unable, exercise your own reasoning (ijtihad) and spare no effort. And if you are still unable, admit it and do not feel ashamed."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 8889