To be precise: You'll likely need to consult a repair manual specific to your 1997 GMC Sonoma 2.2L engine. A Haynes or Chilton manual would show a diagram and give precise location details. The location *should* be as described above, but variations are possible.
Before attempting any work: Disconnect the negative battery terminal to prevent electrical shorts.
It's always best to use a repair manual or online diagrams specific to your year and engine. Searching for "1997 GMC Sonoma 2.2L crankshaft position sensor location" with images should provide visual confirmation.