I want to use IML's table command to create a table with spanned column headings as shown in the image below.
How can I specify that the individual words of the column headings be stacked up vertically into rows, essentially transposing the long line of text into a column of words?
I know that I can use the submit/endsubmit block to access PROC TABULATE or PROC REPORT, but I want to stay within the PROC IML environment.
data class;
set sashelp.class;
obs+1;
keep obs age weight height;
run;
proc iml;
use class;
read all var {obs};
read all var {age weight height} into x;
close;
print x[l='Wang-Mendel Rules' r=obs
c={'Rule(*ESC*)nWeighted'
'Weighted(*ESC*)nAverage(*ESC*)nOf(*ESC*)nOutput'
'Weighted(*ESC*)nDeviation(*ESC*)nOf(*ESC*)nOutput'}];
quit;
In general, IML provides much less control over the output as compared to PROC REPORT, so one option is to write the data to a SAS data set and then call PROC REPORT.
If you really want to try to do this in IML, I suggest you define the ODS template that you want (including how you want the headers to split) and then print the table by using the TEMPLATE= option in the TablePrint subroutine. See "Advanced Printing of Tables" in the documentation. If you don't know how to create the ODS template, ask in the Programming->ODS and Base reporting community.
BTW, I think you are using the word "spanned column" differently than the ODS folks do. A spanned column is a header that extends across two or more columns. I think the words you want to use are "split the column header at certain characters."
data class;
set sashelp.class;
obs+1;
keep obs age weight height;
run;
proc iml;
use class;
read all var {obs};
read all var {age weight height} into x;
close;
print x[l='Wang-Mendel Rules' r=obs
c={'Rule(*ESC*)nWeighted'
'Weighted(*ESC*)nAverage(*ESC*)nOf(*ESC*)nOutput'
'Weighted(*ESC*)nDeviation(*ESC*)nOf(*ESC*)nOutput'}];
quit;
Thanks for the tip on using (*ESC*)n to delimit the words in the column headers. I was not aware of this linguistic feature. Where is it documented?
@rbettinger wrote:
Thanks for the tip on using (*ESC*)n to delimit the words in the column headers. I was not aware of this linguistic feature. Where is it documented?
That is ODS functionality. It has nothing to do with IML.
If you try that code and send the output to the plain old listing destination then those characters are just printed the same as the other characters.
The SAS System 09:18 Sunday, August 6, 2023 39 Wang-Mendel Rules Rule(*ESC*)nWeighted Weighted(*ESC*)nAverage(*ESC*)nOf(*ESC*)nOutput Weighted(*ESC*)nDeviation(*ESC*)nOf(*ESC*)nOutput 14 112.5 69 13 84 56.5 13 98 65.3 14 102.5 62.8 14 102.5 63.5 12 83 57.3 12 84.5 59.8 15 112.5 62.5 13 84 62.5 12 99.5 59 11 50.5 51.3 14 90 64.3 12 77 56.3 15 112 66.5 16 150 72 12 128 64.8 15 133 67 11 85 57.5 15 112 66.5
As Tom says, you can use escape characters to insert inline formatting by using ODS markup commands. For details and some references to the doc and to papers, see https://blogs.sas.com/content/iml/2023/08/16/unicode-symbols-escapechar-sas.html
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.