# Problem to import SPSS/SAS Data

**URL:** <https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728>\
**Category:** Statistics\
**Created:** [May 1, 2019, 10:12am UTC](https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728 "2019-05-01T10:12:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessandro\_Vivas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessandro_vivas/32/7389_2.png) [@Alessandro\_Vivas](https://discourse.julialang.org/u/Alessandro_Vivas)\
**Post date:** [May 1, 2019, 10:12am UTC](https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728/1 "2019-05-01T10:12:12Z")

</div>

I’m working with SPSS data, but I’m not able to import data. When I import with ReadStat I am not able to convert data to DataFrame. And when I use StatFiles I’m having import error problems. What is the correct way to import data in SPSS format?

```julia
using ReadStat;
using DataFrames;
using StatFiles;

Escola=read_sas7bdat("./Datasets/Pisa/Escola/cy6_ms_cmb_sch_qqq.sas7bdat")

df = DataFrame(load("./Datasets/Pisa/Escola/cy6_ms_cmb_sch_qqq.sas7bdat")

```

Error with StatFiles:

```julia

ArgumentError: no default `Tables.columns` implementation for type: StatFiles.StatFile

Stacktrace:
 [1] columns at /Users/alessandrovivas/.julia/packages/Tables/qlc3J/src/fallbacks.jl:156 [inlined]
 [2] DataFrame(::StatFiles.StatFile) at /Users/alessandrovivas/.julia/packages/DataFrames/IKMvt/src/other/tables.jl:21
 [3] top-level scope at In[16]:7

```

Thanks,

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 1, 2019, 11:21am UTC](https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728/2 "2019-05-01T11:21:04Z")

</div>

Downloaded example data from here [SAS Data files](http://www.principlesofeconometrics.com/sas.htm), using julia 1.1:

```julia
using ReadStat;
using DataFrames;
d=read_sas7bdat("airline.sas7bdat")
df=DataFrame(d.data,Symbol.(d.labels))

```

The `ReadStatDataFrame` struct has the following definition:

```julia
mutable struct ReadStatDataFrame
    data::Vector{Any}
    headers::Vector{Symbol}
    types::Vector{DataType}
    labels::Vector{String}
    formats::Vector{String}
    storagewidths::Vector{Csize_t}
    measures::Vector{Cint}
    alignments::Vector{Cint}
    val_label_keys::Vector{String}
    val_label_dict::Dict{String, Dict{Any,String}}
    rows::Int
    columns::Int
    filelabel::String
    timestamp::DateTime
    format::Clong

    ReadStatDataFrame() = 
        new(Any[], Symbol[], DataType[], String[], String[], Csize_t[], Cint[], Cint[],
        String[], Dict{String, Dict{Any,String}}(), 0, 0, "", Dates.unix2datetime(0), 0)
end

```

From this

> For integration with packages like [DataFrames.jl](https://github.com/JuliaData/DataFrames.jl) you should use the [StatFiles.jl](https://github.com/queryverse/StatFiles.jl) package.

> **[GitHub - queryverse/ReadStat.jl: Read files from Stata, SAS, and SPSS](https://github.com/queryverse/ReadStat.jl)**
>
> Read files from Stata, SAS, and SPSS. Contribute to queryverse/ReadStat.jl development by creating an account on GitHub.

I didn’t found the way to do it. Maybe @davidanthoff finds some time to clarify.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 1, 2019, 11:28am UTC](https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728/3 "2019-05-01T11:28:15Z")

</div>

Or maybe

```julia
df=DataFrame(d.data,d.headers)

```

is better. In the example data the labels are more descriptive, so I used them at first.

---

<div class="post-metadata">

**Author:** ![Alessandro\_Vivas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessandro_vivas/32/7389_2.png) [@Alessandro\_Vivas](https://discourse.julialang.org/u/Alessandro_Vivas)\
**Post date:** [May 1, 2019, 12:05pm UTC](https://discourse.julialang.org/t/problem-to-import-spss-sas-data/23728/4 "2019-05-01T12:05:48Z")

</div>

Thank you! It works!
