Praise be to Allaah.
It is Sunnah to do that. Abu Hurayrah (may Allaah be pleased with him) reported that the Prophet (peace and blessings of Allaah be upon him) said: “When one of you joins a gathering, let him say salaam. When he wants to get up and leave, let him say salaam. The former is not more important than the latter.”
(Reported by al-Tirmidhi, who said, It is a hasan hadeeth. ).