I suspect the problem to be with something else other then the code. SIM900 has a specific led pattern to indicate connection with network. So, first step would be notice blinking rates of the leds and there is a change then it's connected to network(In that case problem will be with the code). If not, then there can be multiple possibilities, please mention your SIM specifications(like company, 3g/4g etc). Also, try taking the module on the roof-top of somewhere with a good signal strength.
Did you used that module/SIM ever before with some other SIM/module? I had an incident where there was a fault in my module itself.