If you signed a purchase contract stating that the buyer would finance can you cancel the contract if you can't get a loan?

It depends upon the specific terms and conditions of the contract. If the contract simply states it is the buyer's obligation to secure financing, then you can NOT cancel the contract. If the contract states that the agreement is conditional upon the buyer's ability to secure a loan, then you CAN cancel the contract.