Skip to content

Commit e415fd5

Browse files
committed
Fix support for type 'E' multiple response sets in SPSS SAV files
1 parent b2d5407 commit e415fd5

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/spss/readstat_sav.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ typedef struct sav_ctx_s {
122122
#define SAV_RECORD_SUBTYPE_INTEGER_INFO 3
123123
#define SAV_RECORD_SUBTYPE_FP_INFO 4
124124
#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS 7
125+
#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS_V14 19
125126
#define SAV_RECORD_SUBTYPE_PRODUCT_INFO 10
126127
#define SAV_RECORD_SUBTYPE_VAR_DISPLAY 11
127128
#define SAV_RECORD_SUBTYPE_LONG_VAR_NAME 13

src/spss/readstat_sav_parse_mr_name.rl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,28 @@
9494

9595
nc = (alnum | '_' | '.' ); # name character (including dots)
9696
name = nc+ '=' > extract_mr_name;
97-
type = ('C' | 'D'){1} > extract_mr_type;
97+
98+
# Define types
99+
c_type = 'C' > extract_mr_type;
100+
d_type = 'D' > extract_mr_type;
101+
e_type = 'E' > extract_mr_type;
102+
103+
# For type E, we need an optional pattern for the additional parameters
104+
e_params = ' ' ('1' | '11') ' ';
105+
98106
counted_value = digit* ' ' > extract_counted_value;
99107
label = digit+ ' '+ > extract_label;
100108

101109
end = (space | '\0'); # subvar token terminator
102110
subvariable = (nc+ end >extract_subvar);
103111

104-
main := name type counted_value label subvariable+;
112+
# Define patterns for each type
113+
c_pattern = c_type counted_value label subvariable+;
114+
d_pattern = d_type counted_value label subvariable+;
115+
e_pattern = e_type e_params counted_value label subvariable+;
116+
117+
# Main pattern is one of the type patterns
118+
main := name (c_pattern | d_pattern | e_pattern);
105119

106120
write data nofinal noerror;
107121
}%%
@@ -142,7 +156,7 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
142156
result->counted_value = mr_counted_value;
143157
result->subvariables = mr_subvariables;
144158
result->num_subvars = mr_subvar_count;
145-
if (result->type == 'D') {
159+
if (result->type == 'D' || result->type == 'E') {
146160
result->is_dichotomy = 1;
147161
}
148162

src/spss/readstat_sav_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
13641364
retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx);
13651365
if (retval != READSTAT_OK)
13661366
goto cleanup;
1367-
} else if (subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS) {
1367+
} else if (subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS || subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS_V14) {
13681368
if (ctx->mr_sets != NULL) {
13691369
retval = READSTAT_ERROR_BAD_MR_STRING;
13701370
goto cleanup;

0 commit comments

Comments
 (0)