engine stalling and cutting out

I have a 96 Ranger. Periodically it runs as though someone is switching the key off and on as fast as they can.It sits and idles like there isn't a problem, but when you give it gas it acts up. It happens about every six months or so. I have changed the fuel filter, cleaned the MAS, and checked all the wiring connections. Took it for a drive and it seems to be running ok for now. Any ideas on what would be my next step if it happens again?
0