Nik
Nik

Reputation: 495

Nested formats in SAS are truncated to 40 characters when printing

If I create a format that includes a long label, it prints just fine. However, if I nest that format within a new format using square brackets, formatted values will be truncated to 40 characters upon printing.

I print this single value table two times, once using a normal format and once using a nested format. In both cases, I expect the formatted value to be the entire English alphabet twice in a row. However, the second time, when I use the nested format, it truncates the printed value to be only 40 characters long.

PROC FORMAT;
VALUE longfmt
    1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
VALUE nestfmt
    1 = [longfmt.];
QUIT;

PROC SQL;
CREATE TABLE tbl (col NUM);
INSERT INTO tbl VALUES (1);

SELECT col FORMAT=longfmt. FROM tbl;
SELECT col FORMAT=nestfmt. FROM tbl;
QUIT;

Upvotes: 4

Views: 38

Answers (1)

Nik
Nik

Reputation: 495

Thanks to Tom, I now understand I should have specified the width of the first format when I nested it in the second format. In other words, I changed [longfmt.] to [longfmt52.]:

PROC FORMAT;
VALUE longfmt
    1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
VALUE nestfmt
    1 = [longfmt52.];
QUIT;

PROC SQL;
CREATE TABLE tbl (col NUM);
INSERT INTO tbl VALUES (1);

SELECT col FORMAT=longfmt. FROM tbl;
SELECT col FORMAT=nestfmt. FROM tbl;
QUIT;

Upvotes: 4

Related Questions