How to save SAS data into RData format


#1

I have already import dataset but cannot save into RData format. code given below.

url<-"http://fiji/Dataset-fiji_sas.sas5bdat"
setwd(file.path("C:/Users/atamani/Desktop/Mydata"))
local<-file.path("Dataset-fiji_sas.sas5bdat")
download.file(url,local)

save(fiji, file = "fiji_sas.RData")
fiji

Please advise
Thanks


#2

Hi! Welcome!

Have you posted all of your code? If so, then I think you're missing a step. Your code downloads the file Dataset-fiji_sas.sas5bdat to C:/Users/atamani/Desktop/Mydata/Dataset-fiji_sas.sas5bdat. but it doesn't otherwise load or import that file into R. So when you go to save an .RData file, there is no fiji object to be saved, since no fiji object has been created yet by your code. You need to write code that will import the downloaded file into an object called fiji (this would go between the downloading step and the saving step).

P.S. Around here, we encourage people to format their code as code, since it makes it easier to read. You can read about how to do so in this FAQ, or just use the </> button at the top of the post editing box :slightly_smiling_face:


#3

As @jcblum mentioned, the download.file() only saves a copy of the file at the chosen path. If you want to load a SAS dataset as a data.frame, you can use the haven package after downloading the file:

## Install haven if you don't have it:
# install.packages("haven")
library(haven)
fiji <- read_sas(local)
save(fiji, file = "fiji_sas.RData")