BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

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? 

3 REPLIES 3
PaigeMiller
Diamond | Level 26
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
Tom
Super User Tom
Super User

Why are you trying to run R code in SAS?

What is a SAV file?  Do you mean you have an SPSS dataset?

Reeza
Super User
That's R code, not SAS.

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 467 views
  • 2 likes
  • 4 in conversation