Hi Tom:
Here's the full code. Sorry, my bad. I was planning to color code and annotate in the screen shot but then got called away and so I just posted it without much extra commenting.
data fakedata;
infile datalines dlm=',';
input Col1 $ Col2 $ Treatment Location Value;
datalines;
A, A, 1, 1, 1
A, A, 1, 2, 2
A, A, 2, 1, 3
A, A, 2, 2, 4
A, B, 1, 1, 5
A, B, 1, 2, 6
A, B, 2, 1, 7
A, B, 2, 2, 8
;
run;
** need to assign values to the macro variables for N/Treatment before this proc format runs;
** or else hardcode the values in the format;
** or else use a different technique to get the headers;
%let t1_cnt = 111;
%let t2_cnt = 222;
proc format;
value treatf 1="Treatment 1/N=&t1_cnt"
2="Treatment 2/N=&t2_cnt";
value locf 1="Location 1"
2="Location 2";
run;
title;
ods escapechar='~';
Title '1) Using ESCAPECHAR in column header for Col1 and Col2';
title2 'But use SPLIT default character for Treatment labels';
Proc report data = fakedata
style(header)={vjust=b};
column (" Label ~n more label" Col1 ) ("Label ~n more label" Col2) Treatment,Location,Value;
define Col1 / '' group order=internal;
define Col2 / '' group order=internal;
define treatment / '' across order=internal f=treatf.;
define location/ '' across order=internal f=locf.;
define Value/sum '';
run;
Title '2) Using default SPLIT for line feed in header';
title2 'adding N= as second line for Treatment';
Proc report data = fakedata
style(header)={vjust=b};
column ('Label/more label' Col1) ('Label/more label' Col2) Treatment,Location,Value;
define Col1 / '' group order=internal;
define Col2 / '' group order=internal;
define treatment / '' across order=internal f=trtnf.;
define location/ '' across order=internal f=locf.;
define Value/sum '';
run;
title;
Notice that all of the column headers in the DEFINE statements are turned off with the empty or null '' as the label -- that means the spanning headers in the COLUMN statement will be used for Col1 and Col2 and the VALUES for TREATMENT and LOCATION will be visible for the OTHER HEADERS. Example #3 blanks all headers in the DEFINE, but example #4 only blanks some headers:
Here's the code that used the same FAKEDATA file to generate those outputs:
Title '3) show ALL headers including spanning Headers';
Proc report data = fakedata
style(header)={vjust=b};
column ('Label/more label' Col1) ('Label/more label' Col2) Treatment,Location,Value;
define Col1 / 'Col1' group order=internal;
define Col2 / 'Col2' group order=internal;
define treatment / 'Treatment' across order=internal f=trtnf.;
define location/ 'Location' across order=internal f=locf.;
define Value/sum 'Value';
run;
Title '4) Only blank out some headers';
Proc report data = fakedata
style(header)={vjust=b};
column ('Label/more label' Col1) ('Label/more label' Col2) Treatment,Location,Value;
define Col1 / 'Col1' group order=internal;
define Col2 / 'Col2' group order=internal;
define treatment / '' across order=internal f=trtnf.;
define location/ '' across order=internal f=locf.;
define Value/sum '';
run;
title;
Cynthia
... View more