Rick doesn't appear to have all that many friends, but Sam is certainly one of them. He might be Rick's best friend. It appears he's the only other person in Casablanca (until Ilsa shows up) that knew him in his past life, so Rick must like him enough to keep him around. We see further evidence of this later on, when Rick sells his place to Ferrari but makes him promise to continue giving Sam 25% of the profits (which is even more than he was making before). In fact, Rick might like Sam more than he likes himself. Not that that's saying much.
We don't get a ton of back-story on Sam here, but he's pretty vital in bringing Rick and Ilsa back together again, his rendition of the song "As Time Goes By" acting as an emotional fulcrum to take them back to a time and place where they were happy and in love. You know, before all that dang time went by.