Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ libreadstat_la_SOURCES = \
src/sas/readstat_sas7bdat_write.c \
src/sas/readstat_sas_rle.c \
src/sas/readstat_sas_rdc.c \
src/sas/readstat_cport_read.c \
src/sas/readstat_xport.c \
src/sas/readstat_xport_read.c \
src/sas/readstat_xport_write.c \
Expand Down Expand Up @@ -96,6 +97,9 @@ EXTRA_DIST = \
resources/compression_type_0x0d.sas7bdat \
resources/format_with_default_32bit.sas7bcat \
resources/format_with_default_64bit.sas7bcat \
resources/cport_basic_win94.xpt \
resources/cport_basic_viya_nocompress.xpt \
resources/cport_encoding_viya.xpt \
resources/sav_missing_continuations.sav

include_HEADERS = src/readstat.h
Expand All @@ -113,6 +117,7 @@ noinst_HEADERS = \
src/sas/readstat_sas.h \
src/sas/readstat_sas_rle.h \
src/sas/readstat_sas_rdc.h \
src/sas/readstat_cport.h \
src/sas/readstat_xport.h \
src/sas/readstat_xport_parse_format.h \
src/spss/readstat_por.h \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Originally developed for [Wizard](https://www.wizardmac.com/), ReadStat is a
command-line tool and MIT-licensed C library for reading files from popular
stats packages. Supported data formats include:

* SAS: SAS7BDAT (binary file) and XPORT (transport file)
* SAS: SAS7BDAT (binary file), XPORT (transport file) and CPORT (transport file, read only)
* Stata: DTA (binary file) versions 104-119
* SPSS: POR (portable file), SAV (binary file), and ZSAV (compressed binary)

Expand Down Expand Up @@ -131,7 +131,7 @@ Standard usage:

Where:

* `<input file>` ends with `.dta`, `.por`, `.sav`, `.sas7bdat`, or `.xpt`and
* `<input file>` ends with `.dta`, `.por`, `.sav`, `.sas7bdat`, `.xpt`, `.cpt` or `.cport`, and
* `<output file>` ends with `.dta`, `.por`, `.sav`, `.sas7bdat`, `.xpt` or `.csv`

If [libxlsxwriter](http://libxlsxwriter.github.io) is found at compile-time, an
Expand Down
2 changes: 2 additions & 0 deletions VS17/ReadStat.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<ClCompile Include="..\src\sas\readstat_sas7bdat_write.c" />
<ClCompile Include="..\src\sas\readstat_sas_rle.c" />
<ClCompile Include="..\src\sas\readstat_sas_rdc.c" />
<ClCompile Include="..\src\sas\readstat_cport_read.c" />
<ClCompile Include="..\src\sas\readstat_xport.c" />
<ClCompile Include="..\src\sas\readstat_xport_read.c" />
<ClCompile Include="..\src\sas\readstat_xport_write.c" />
Expand Down Expand Up @@ -245,6 +246,7 @@
<ClInclude Include="..\src\sas\readstat_sas.h" />
<ClInclude Include="..\src\sas\readstat_sas_rle.h" />
<ClInclude Include="..\src\sas\readstat_sas_rdc.h" />
<ClInclude Include="..\src\sas\readstat_cport.h" />
<ClInclude Include="..\src\sas\readstat_xport.h" />
<ClInclude Include="..\src\sas\readstat_xport_parse_format.h" />
<ClInclude Include="..\src\spss\readstat_por.h" />
Expand Down
6 changes: 6 additions & 0 deletions VS17/ReadStat.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<ClCompile Include="..\src\sas\readstat_sas_rdc.c">
<Filter>Source Files\sas</Filter>
</ClCompile>
<ClCompile Include="..\src\sas\readstat_cport_read.c">
<Filter>Source Files\sas</Filter>
</ClCompile>
<ClCompile Include="..\src\sas\readstat_sas7bcat_read.c">
<Filter>Source Files\sas</Filter>
</ClCompile>
Expand Down Expand Up @@ -212,6 +215,9 @@
<ClInclude Include="..\src\sas\readstat_sas_rdc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\sas\readstat_cport.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\sas\readstat_xport.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
6 changes: 5 additions & 1 deletion man/readstat.man
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ should be a file with one of the following extensions:
SAS binary file, created with SAS version 7 or newer
.TP
.IR xpt
SAS portable file, version 5 or version 8, created with the SAS XPORT command
SAS portable file, version 5 or version 8, created with the SAS XPORT command,
or SAS transport file created with PROC CPORT (read only)
.TP
.IR cpt ", " cport
SAS transport file created with PROC CPORT (read only)
.TP
.IR sav
SPSS uncompressed binary file
Expand Down
Binary file added resources/cport_basic_viya_nocompress.xpt
Binary file not shown.
Binary file added resources/cport_basic_win94.xpt
Binary file not shown.
Binary file added resources/cport_encoding_viya.xpt
Binary file not shown.
11 changes: 7 additions & 4 deletions src/bin/readstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ static void print_version(void) {
}

#if HAVE_ZLIB
#define INPUT_FORMATS "dta|por|sav|sas7bdat|xpt|zsav"
#define READ_WRITE_FORMATS "dta|por|sav|sas7bdat|xpt|zsav"
#else
#define INPUT_FORMATS "dta|por|sav|sas7bdat|xpt"
#define READ_WRITE_FORMATS "dta|por|sav|sas7bdat|xpt"
#endif

/* SAS CPORT files can be read, but not written */
#define INPUT_FORMATS READ_WRITE_FORMATS "|cpt|cport"

#if HAVE_XLSXWRITER
#define OUTPUT_FORMATS INPUT_FORMATS "|csv|xlsx"
#define OUTPUT_FORMATS READ_WRITE_FORMATS "|csv|xlsx"
#else
#define OUTPUT_FORMATS INPUT_FORMATS "|csv"
#define OUTPUT_FORMATS READ_WRITE_FORMATS "|csv"
#endif

static void print_usage(const char *cmd) {
Expand Down
10 changes: 10 additions & 0 deletions src/bin/util/file_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ rs_format_e readstat_format(const char *filename) {
if (strncasecmp(filename + len - 4, ".xpt", 4) == 0)
return RS_FORMAT_XPORT;

/* SAS CPORT files are read through the XPORT reader */
if (strncasecmp(filename + len - 4, ".cpt", 4) == 0)
return RS_FORMAT_XPORT;

if (len < sizeof(".json")-1)
return RS_FORMAT_UNKNOWN;

Expand All @@ -52,6 +56,12 @@ rs_format_e readstat_format(const char *filename) {
if (strncasecmp(filename + len - 5, ".zsav", 5) == 0)
return RS_FORMAT_ZSAV;

if (len < sizeof(".cport")-1)
return RS_FORMAT_UNKNOWN;

if (strncasecmp(filename + len - 6, ".cport", 6) == 0)
return RS_FORMAT_XPORT;

if (len < sizeof(".sas7bdat")-1)
return RS_FORMAT_UNKNOWN;

Expand Down
8 changes: 8 additions & 0 deletions src/sas/readstat_cport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/* SAS CPORT transport files (PROC CPORT), often named .xpt like XPORT
* files. They are read through readstat_parse_xport(). */

#define CPORT_RECORD_LEN 80

int cport_has_signature(const char *record, size_t record_len);
readstat_error_t cport_parse(readstat_parser_t *parser, size_t file_size, void *user_ctx);
Loading