Under normal circumstances, driving without a gas cap is not dangerous. Leaving the gas cap off allows gas to evaporate and escape a car's fuel system, which eventually triggers a check-engine light as the leak is detected, but it is usually not harmful to the car.
Driving without a gas cap can be indirectly dangerous, however. The failure in the evaporation-control system triggers the check-engine light. While the missing cap is causing this error message, a more serious malfunction could occur that would also trigger a check-engine light, and the driver may not realize it due to the previous warning.