0

I want to iterate along a character vector, read from a SAS file containing a string in the character vector as part of the path, then write this data frame into my database. Below is an example of my code that isn't working.

  for (j in c("table1", "table2")) {
    SAS_File_Path <- paste("C:/SAS_files/", j, ".sas7bdat", sep = "")
    if (file.exists(SAS_File_Path)){
        j <- read.sas7bdat(SAS_File_Path)
        sqlSave(ch, j, rownames = FALSE, append = TRUE)
    }
}

The for loop above seems to paste the the path together correctly making something like C:/SAS_files/table1.sas7bdat but then it gets assigned to a data frame named j rather than table1. I need the data frame to be named table1 so I can append it to a pre-existing table in my data frame. Ultimately I want to iterate along a character vector and read a file into into a data frame assigned to the string in that element of the vector.

Any guidance would be greatly appreciated

JanLauGe
  • 2,107
  • 2
  • 12
  • 38
Pat_W
  • 1

0 Answers0