I'm trying to import several SAS datafiles from a folder and then save them back into the folder as R dataframes with the same original SAS dataset name. Everything works except I can't figure out how to save the file with the original file name (i.e., I can't figure out the x in > save(xxx, file = ...).
The code I've tried is as follows:
path <- "path to folder with sas files"
list.files(pattern=".sas7bdat$")
list.filenames<-list.files(pattern=".sas7bdat$")
for (i in 1:length(list.filenames)){
assign(list.filenames[i], read_sas(list.filenames[i]))
filename <- paste(list.filenames[i])
save(list.filenames[i],file = paste0(path, paste(list.filenames[i], "Rdat", sep = ".")))
}
doesn't work...
for (i in 1:length(list.filenames)){
assign(list.filenames[i], read_sas(list.filenames[i]))
filename <- paste(list.filenames[i])
save(list.filenames[[i]],file = paste0(path, paste(list.filenames[i], "Rdat", sep = ".")))
}
doesn't work
for (i in 1:length(list.filenames)){
assign(list.filenames[i], read_sas(list.filenames[i]))
filename <- paste(list.filenames[i])
save(filename,file = paste0(path, paste(list.filenames[i], "Rdat", sep = ".")))
}
Any help on figuring out how to save the files with the original names from list.filenames[i]?