Check your transmission fluid level, if it is ok then I would take it to a shop for diagnostics. There is an electrical/functional issue with one of the shift solenoids. I don't have a lot of experience with them on Subaru's, but on Ford's it requires you to drop the trans pan and replace the solenoid.
Besides verifying the fluid level, the electrical connector on the outside of the transmission could be dirty or otherwise corroded. The solenoid is something that you can replace yourself (again, of a Ford F4EAT, you can do it).