I am a bit confused. If you are recording the audio output of the external keyboard into Sonar, by routing your audio output from the keyboard to input ports of an audio interface, that's a simple connection, but it does not seem this is what you are referring to.
Please correct me if I am reading your post incorrectly. When I read it, I get the sense that you are talking about recording MIDI, and that when you play back the recorded data, your external keyboard is indeed responding to the played back midi data and it is triggering sounds that play through the external keyboard's speakers, but that you are expecting SOUND from your external keyboard to be sent through the USB connection and play back through Sonar, or something like that.
IF the above is kind of what you are doing and seeing, then you need to understand that midi is data only, and not sound in and of itself. And, the USB connection from your external keyboard to the computer does not transfer any audio signal whatsoever, just midi information.
1. If you are trying to hear your external keyboard's internal sounds through the speakers connected through Sonar to your audio interface, than you need to connect instrument cables from the output jack(s) on the back of that keyboard to input jacks on the audio interface, then insert audio tracks into Sonar and set the input to be the same input ports those cables are plugged into.
2. If instead you are wanting to use your external keyboard to trigger sounds from soft-synthesizer plugins within Sonar, then you need to have a midi track send it''s events to a soft-synth in the synth rack in Sonar, then have one or more audio tracks inserted into Sonar with the input set to pick up the output from the soft-synth. Then, those audio tracks will send the generated audio signal from the soft-synths to a bus (master bus by default, or a new bus if you insert one and set up routing from that bus to the master bus).
Anyways, I think it would be helpful if you could please clarify what exactly you are trying to do, and if you are having trouble working with midi, then I also would refer you to the link someone else above posted, on dealing with midi. There is also at least one midi tutorial provided with Sonar, which might help, as well as countless YouTube videos walking you through all aspects of setting up devices and recording/playback of midi in Sonar.
Bob Bone