While I checked this link, I am still struggling in getting a formatted sas file into R as I have a formatted .sas7bdat file (attached here) but when I tried to import it into R
I noticed that all formats were lost.
I used 2 different codes:
## Code 1:
##========
library(haven)
data <- read_sas("C:/Users/mmr2011/OneDrive/R codes/df_nsclc1.sas7bdat", NULL)
## Code 2:
##========
library(sas7bdat)
data("sas7bdat.sources")
data<-read.sas7bdat("C:/Users/mmr2011/OneDrive/R codes/df_nsclc1.sas7bdat", debug= F)
table(data$SEX) # gives me 1 and 2 instead of males and females
# 1 2
#880916 799960
# Then I tried this code (as I have sas catalog folder named format so I added that to my prior code; formats.sas7bcat) as follows
#===============================================================================
data<- read_sas("C:/Users/mmr2011/OneDrive/OneDrive/R codes/df_nsclc1.sas7bdat", catalog_file = "C:/Users/mmr2011/OneDrive/OneDrive/R codes/formats.sas7bcat")
# table(data$SEX)
# 1 2
#50190 66064
While I need them to be as they are in sas as follow
I am using SAS catalog folder in Windows
that is shown below (screenshot No. 5). Also, It is available here
Any advice will be greatly appreciated