How to convert multiple sas dataset to xpt in R

Hi ,
How to convert multiple sas dataset to XPT in R. I am using below code and getting error.
library(haven) >
setwd ("xx")

df <- list()
listsas <- dir(pattern="*.sas7bdat")|
for (k in 1:length(listsas)){ + df[[k]] <- read_sas(listsas[k]) + m<-substr(listsas[[k]],1,2) + path <-paste("x/",m,".xpt",sep="")
write_xpt(df[[k]],path)
}

Error: Writing failure: A provided format string could not be understood.|

Thanks,

Do you have a folder of "x" in your current directory?

Yes I do have folder

Digging in, this seems to be coming from your source file(s).

Perhaps there is something corrupt with your sas7bdat files?

This looks unusual — what did you intend by using the "+" symbols here?

Code is copied from console to paste error

Could you run this, just to see where an error might be triggered, and post a screenshot of the console at that point?

df <- list()
listsas <- dir(pattern="*.sas7bdat")|
for (k in 1:length(listsas)){
  print("file:" |> paste(k))
  df[[k]] <- read_sas(listsas[k]) 
  m<-substr(listsas[[k]],1,2)
  print("prefix:" |> paste(m))
  # path <-paste("x/",m,".xpt",sep="")
  # write_xpt(df[[k]],path)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.