FORMCHAR Option

From sasCommunity

Jump to: navigation, search

The SAS Monospace font includes a series of characters which can be combined to draw the lines and boxes of a table. For example, this code

proc tabulate data=sashelp.class;
class sex age;
table sex, age*f=3.;
run;

will ordinarily generate this in the Output window:
image: boxdrawing.png
However, if this table is copied or otherwise carried to an environment which does not have or does not use the SAS Monospace font, it can look like this

„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†
‚                      ‚          Age          ‚
‚                      ‡ƒƒƒ…ƒƒƒ…ƒƒƒ…ƒƒƒ…ƒƒƒ…ƒƒƒ‰
‚                      ‚11 ‚12 ‚13 ‚14 ‚15 ‚16 ‚
‚                      ‡ƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒ‰
‚                      ‚ N ‚ N ‚ N ‚ N ‚ N ‚ N ‚
‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒ‰
‚Sex                   ‚   ‚   ‚   ‚   ‚   ‚   ‚
‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰   ‚   ‚   ‚   ‚   ‚   ‚
‚F                     ‚  1‚  2‚  2‚  2‚  2‚  .‚
‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒ‰
‚M                     ‚  1‚  3‚  1‚  2‚  2‚  1‚
Šƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒ‹ƒƒƒ‹ƒƒƒ‹ƒƒƒ‹ƒƒƒ‹ƒƒƒŒ

To avoid this, use the FORMCHAR= option to substitute common printable characters (specifically: the hyphen -, the pipe |, and the plus sign +) for the special drawing characters. The output won't look as nice in the SAS Output window, but it should at least look the same wherever you move it.

The FORMCHAR= option is available as a SAS System Option. In addition, several of the procedures which render tabular output (including TABULATE, FREQ, and CALENDAR) support FORMCHAR= as a procedure option.

Here are four variations;

proc tabulate data=sashelp.class formchar="|----|+|---";
class sex age;
table sex, age*f=3.;
run;
------------------------------------------------
|                      |          Age          |
|                      |-----------------------|
|                      |11 |12 |13 |14 |15 |16 |
|                      |---+---+---+---+---+---|
|                      | N | N | N | N | N | N |
|----------------------+---+---+---+---+---+---|
|Sex                   |   |   |   |   |   |   |
|----------------------|   |   |   |   |   |   |
|F                     |  1|  2|  2|  2|  2|  .|
|----------------------+---+---+---+---+---+---|
|M                     |  1|  3|  1|  2|  2|  1|
------------------------------------------------
proc tabulate data=sashelp.class formchar="|-+-+|+|+-+";
class sex age;
table sex, age*f=3.;
run;
+----------------------------------------------+
|                      |          Age          |
|                      |-----------------------|
|                      |11 |12 |13 |14 |15 |16 |
|                      |---+---+---+---+---+---|
|                      | N | N | N | N | N | N |
|----------------------+---+---+---+---+---+---|
|Sex                   |   |   |   |   |   |   |
|----------------------|   |   |   |   |   |   |
|F                     |  1|  2|  2|  2|  2|  .|
|----------------------+---+---+---+---+---+---|
|M                     |  1|  3|  1|  2|  2|  1|
+----------------------------------------------+
proc tabulate data=sashelp.class formchar="|-+++++++++";
class sex age;
table sex, age*f=3.;
run;
+----------------------+-----------------------+
|                      |          Age          |
|                      +---+---+---+---+---+---+
|                      |11 |12 |13 |14 |15 |16 |
|                      +---+---+---+---+---+---+
|                      | N | N | N | N | N | N |
+----------------------+---+---+---+---+---+---+
|Sex                   |   |   |   |   |   |   |
+----------------------+   |   |   |   |   |   |
|F                     |  1|  2|  2|  2|  2|  .|
+----------------------+---+---+---+---+---+---+
|M                     |  1|  3|  1|  2|  2|  1|
+----------------------+---+---+---+---+---+---+
proc tabulate data=sashelp.class formchar="|-+++|+|+++";
class sex age;
table sex, age*f=3.;
run;
+----------------------+-----------------------+
|                      |          Age          |
|                      |---+---+---+---+---+---|
|                      |11 |12 |13 |14 |15 |16 |
|                      |---+---+---+---+---+---|
|                      | N | N | N | N | N | N |
|----------------------+---+---+---+---+---+---|
|Sex                   |   |   |   |   |   |   |
|----------------------|   |   |   |   |   |   |
|F                     |  1|  2|  2|  2|  2|  .|
|----------------------+---+---+---+---+---+---|
|M                     |  1|  3|  1|  2|  2|  1|
+----------------------+---+---+---+---+---+---+

To restore the default value to the system option, on an ASCII system, use this code:

options formchar = '82838485868788898A8B8C'x ;

References

Personal tools