- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to read a SAV file into SAS then write it as CSV. Below is an example of what someone gave me to do. What they gave me is in bold. I only changed the file path names.
library(haven)
library(readr)
HNIR62FL_data_2 <-
read_sav("C:\Users\gtuck\OneDrive\Documents\Gretchen Dissertation\SAS\Original Data Set")
write_csv(x=HNIR62FL_data_2, path="C:\Users\gtuck\OneDrive\Documents\Gretchen Dissertation\SAS\CSV.csv")
I received an error message when I ran the above. The error message is:
16 library(haven)
-------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
17 library(readr)
18 HNIR62FL_data_2 <-
19 read_sav("C:\Users\gtuck\OneDrive\Documents\Gretchen Dissertation\SAS\Original Data Set")
20 write_csv(x=HNIR62FL_data_2, path="C:\Users\gtuck\OneDrive\Documents\Gretchen
20 ! Dissertation\SAS\CSV.csv")
I don't know what I need to do. What does the two library names mean? Can they be called anything? What is the HNIR62FL_data_2<- for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
library(haven)
library(readr)
HNIR62FL_data_2 <-
read_sav("C:\Users\gtuck\OneDrive\Documents\Gretchen Dissertation\SAS\Original Data Set")
write_csv(x=HNIR62FL_data_2, path="C:\Users\gtuck\OneDrive\Documents\Gretchen Dissertation\SAS\CSV.csv")
These are not SAS statements.
There is no library statement or function in SAS. There is a LIBNAME command, which looks nothing like the library statement you show and would not be needed to read a file.
Similarly, the rest of your code also does not use SAS statements or SAS functions.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why are you trying to run R code in SAS?
What is a SAV file? Do you mean you have an SPSS dataset?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can do this in SAS though.
proc import datafile = "c:\data\hsb2.sav" out= work.hsb2;
run;
proc export data=hsb2 outfile='C:\data/hsb2.csv' dbms=csv replace;
run;