I've been playing classical guitar for a few years and my theory is not bad. I also think that I am really good at detecting relative pitch and chords. I can play most of the things (solo or chords) I hear by ear, and say if a chord is major, minor etc.
The problem is that, I cannot detect the absolute pitch easily. Sometimes I remember a song that I was listening some time ago, and while it plays in my mind I can play it on my guitar, too. And when I start playing the song on my computer, what I see generally is that I just transposed whole the song without knowing. Sometimes it is only a half step, sometimes half a scale. Also, I can say the scale of a song, but not the key.
Is there any special exercise that I can do to improve this?