Skip to content

Commit fdf4e1e

Browse files
committed
SAS reader: read trailing format (.d) digits
1 parent 3438f34 commit fdf4e1e

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/sas/readstat_sas7bdat_read.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ typedef struct col_info_s {
2020
uint64_t offset;
2121
uint32_t width;
2222
int type;
23-
int format_len;
23+
int format_width;
24+
int format_digits;
2425
} col_info_t;
2526

2627
typedef struct subheader_pointer_s {
@@ -376,8 +377,10 @@ static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subhe
376377
if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
377378
goto cleanup;
378379

379-
if (ctx->u64)
380-
ctx->col_info[ctx->col_formats_count-1].format_len = sas_read2(&subheader[24], ctx->bswap);
380+
if (ctx->u64) {
381+
ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[24], ctx->bswap);
382+
ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[26], ctx->bswap);
383+
}
381384
ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref(
382385
ctx->u64 ? &subheader[46] : &subheader[34], ctx);
383386
ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref(
@@ -693,8 +696,13 @@ static readstat_variable_t *sas7bdat_init_variable(sas7bdat_ctx_t *ctx, int i,
693696
goto cleanup;
694697
}
695698
size_t len = strlen(variable->format);
696-
if (len && ctx->col_info[i].format_len) {
697-
snprintf(variable->format + len, sizeof(variable->format) - len, "%d", ctx->col_info[i].format_len);
699+
if (len && ctx->col_info[i].format_width) {
700+
len += snprintf(variable->format + len, sizeof(variable->format) - len,
701+
"%d", ctx->col_info[i].format_width);
702+
}
703+
if (len && ctx->col_info[i].format_digits) {
704+
len += snprintf(variable->format + len, sizeof(variable->format) - len,
705+
".%d", ctx->col_info[i].format_digits);
698706
}
699707
if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label),
700708
ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {

0 commit comments

Comments
 (0)