There are a few things that would cause this problem.
The first and most common would be the switch itself is bad. the next would be a bad 4wheel drive encoder motor, this is the motor on the transfer case that is used to operate the 4wheel drive. The last would be the 4 wheel drive module.
You will need to do some testing, if the four wheel drive is working and goes in and out of 4 wheel drive then i would say it the switch. if it does not work correctly it may still be the switch or one of the components i listed above.I have enclosed a wiring diagram, you will need to do some testing to check system, first make sure all fuses are good. the fuses that operate the 4wd are listed on diagram, it will also tell you the location of each part. you will need to test front axle actuator and selector motor and switch, you will need a test light and a meter. hope this is helpful, good day.