Using miles is a good option here, especially *A miles due to the regional network.
I recently redeemed a one-way from Panama City to Boston, and had a free weekend to kill so.......Instead of PTY-BOS, I booked PTY-MGA(24 hours)-GUA (24 hours)-PTY-BOS. Same 17.5k miles as the non-stop and only 50$ more in taxes.
It'd be very easy to do RDU-UA Hub-SJO (24 hours)-PTY for 17.5 miles in economy.
Of course, you'd have to have some knowledge of miles and how to obtain them and use them more economically than purchasing the plane ticket outright.