SD card works in setup but not in loop

Your code does not compile.
I think there is a need to include a library.

Maybe SD.h????

And

sketch.ino: In function 'void setup()':
sketch.ino:23:3: error: 'setTime' was not declared in this scope
setTime(12, 0, 0, 1, 1, 2022);

And

sketch.ino: In function 'void loop()':
sketch.ino:49:22: error: 'pressure' was not declared in this scope
myFile.println(pressure);

sketch.ino:51:20: error: 'temperature' was not declared in this scope
myFile.print(temperature);