Can anyone help me write a R data frame as a SAS data set?

后端 未结 3 2023
遇见更好的自我
遇见更好的自我 2021-02-08 14:10

In R, I have used the write.foreign() function from the foreign library in order to write a data frame as a SAS data set.

write         


        
3条回答
  •  春和景丽
    2021-02-08 15:14

    write.foreign with option package="SAS" actually writes out a comma-delimited text file and then creates a script file with SAS statements to read it in. You have to run SAS and submit the script to turn the text file into a SAS dataset. Your call should look more like

    write.foreign(df=test.df, datafile="test.csv", codefile="test.sas", package="SAS")
    

    Note the different extension. Also, write.foreign writes factor variables as numeric variables with a format controlling their appearance -- ie, the R definition of a factor. If you just want the character representation, you'll have to convert the factors via as.character before exporting.

提交回复
热议问题