Hey, I'm just a beginner. But I just had a similar problem getting the SD card to store data.
Is chipSelect= 4 for the SD? If yes:
In your code you got: pinMode(SS, OUTPUT);
"SS" is not correct. It should be "chipSelect".
You may also want to store the data more frequently using: dataFile.flush();
Gerry