admin管理员组

文章数量:1305969

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;

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;
Share Improve this question asked Feb 3 at 15:20 NikNik 4954 silver badges8 bronze badges 2
  • 3 You did not include any WIDTH value in your format specification. What did you set the DEFAULT width to when you defined the format? – Tom Commented Feb 3 at 15:34
  • Thank you! This enriches my understanding of formats. – Nik Commented Feb 3 at 15:58
Add a comment  | 

1 Answer 1

Reset to default 4

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;

本文标签: square bracketNested formats in SAS are truncated to 40 characters when printingStack Overflow