Writing to microSD and Sampling Rate

I am using an Arduino Nano to read and record 5 voltages on the analog pins. I'm writing the values to a microSD card via a HiLetgo microSD module (5pcs Micro SD Carte TF Adater Reader Module,Shenzhen HiLetgo Technology Co., Ltd). Right now, the device records about 38 data points per second, and I'd like to get to about 80. It's my impression that because the default clock speed for the ATMEGA 328 is 16MHz, and the default prescale factor is 128, I could in theory be getting 9600 Hz for my sampling rate.

What is holding me back? Each time the device samples, it has to open and then close the file. Is that process lengthy, and slowing me down? Is there a way I can leave the file open, but somehow still close it when I'm done writing? I tried leaving it open and never closing it, and it didn't save anything.

Yes, opening and closing the file is a lengthy process.

If you opened it, never closed it, and it didn't save anything...Is this because you wrote less than 512 bytes? 512 is the size of a block on the SD card.

Not solving your problem.

A standard analogRead takes approx. 100 microseconds. 5 of them take approx. 500 microseconds. But you have to do dummy reads in between the reads of different channel. And hence you will probably not be able to achieve better than 1000 reads / second; plenty for your need though.

Dummy read example

void loop()
{
  analogRead(A0);
  int val0 = analogRead(A0);

  analogRead(A1);
  int val1 = analogRead(A1);

  ...
  ...
}

Regarding your problem: do you write to SD after every analogRead or do you collect the 5 samples and write them? Opening and closing files is expensive (as mentioned). You can consider a flush after writing the 5 samples.

Notes:
1)
Not showing your code just makes us guess.
2)
Not knowing your specifications (e.g. for how long does it have to record (a minute, days, ...)) makes it impossible to advise on alternatives; e.g. store in an array and when done, write to SD.

The device records for no more than two hours, no less than 10 minutes each time. I'm doing all 5 reads, then printing time, the 5 values, then a couple of other variables that don't need to be read each time. My coding skills are not very elegant, I'd be thrilled to learn that I could use an array or something to cut down on time.

The following is in the loop, the voltage variables are "floats" and the k, j variables are integers.

  voltage1 =  analogRead(A3);
  voltage2 = analogRead(A4);
  voltage3 =  analogRead(A5);
  voltage4 = analogRead(A6); 
  voltage5 = analogRead(A7);
  k=0;

myFile = SD.open(fileName, FILE_WRITE);
    if (myFile){
    myFile.print(millis());
    myFile.print(",");
    myFile.print(voltage1);
    myFile.print(",");
    myFile.print(voltage2);
    myFile.print(",");
    myFile.print(voltage3);
    myFile.print(",");
    myFile.print(voltage4);
    myFile.print(",");
    myFile.print(voltage5);
    myFile.print(",");
    myFile.print(j);
    myFile.print(",");
    myFile.println(k);
    myFile.close();

Why the use of floats? analogRead() returns an integer.

You can try this approach

voltage1 =  analogRead(A3);
voltage2 = analogRead(A4);
voltage3 =  analogRead(A5);
voltage4 = analogRead(A6);
voltage5 = analogRead(A7);
k = 0;


// if file not open yet
if (!myFile) {
  myFile = SD.open(fileName, FILE_WRITE);
}


if (myFile) {
  myFile.print(millis());
  myFile.print(",");
  myFile.print(voltage1);
  myFile.print(",");
  myFile.print(voltage2);
  myFile.print(",");
  myFile.print(voltage3);
  myFile.print(",");
  myFile.print(voltage4);
  myFile.print(",");
  myFile.print(voltage5);
  myFile.print(",");
  myFile.print(j);
  myFile.print(",");
  myFile.println(k);
  myFile.flush();
}

You just need to find a means to close the file, e.g. based on number of samples or a button or ...