BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rbettinger
Pyrite | Level 9

I want to use IML's table command to create a table with spanned column headings as shown in the image below.image.png

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

Ksharp_0-1691666745890.png

 

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

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."  

 

Ksharp
Super User
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;

Ksharp_0-1691666745890.png

 

rbettinger
Pyrite | Level 9

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?

Tom
Super User Tom
Super User

@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




Rick_SAS
SAS Super FREQ

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 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1143 views
  • 2 likes
  • 4 in conversation