BookmarkSubscribeRSS Feed
LAtwood
Calcite | Level 5
I would like to be able to list my column headers in more than one row. For example, I have 20 column headers and I would like the first 10 displayed in the first row of the report and the last 10 to be displayed in the second row of the report.
The first row lists employee information and the second row would list financial information about the employee.
Is this possible?

Thanks
6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Hi:
Without a bit more information, it is hard to come up with an answer to your question. Is your data all in one table or do you have the employee information in one table and the financial information in another table??

Your question is about column headers -- having more than one column header/label in a row -- but what about the data values??? would you want to see the data values occupy only 1 row, too?? Essentially, you would "stack" headers and data values??

What is your destination of choice??? HTML, RTF, PDF???

Normally, PROC PRINT or PROC REPORT would give you something like this (showing only a few rows from SASHELP.CLASS):
[pre]
Name Sex Age Height Weight
Robert M 12 64.8 128
Thomas M 11 57.5 85
[/pre]

If, on the other hand, you wanted to "stack" some of the column headers and values, like this:
[pre]
Name Height
Sex Age Weight
Robert 12 64.8
M 128.0

Thomas 11 57.5
M 85.0
[/pre]

It is possible, but really depends on how your data is structured, what your procedure of choice is, whether you're willing to "pre-process" the data to stack values, what your destination of interest is, etc, etc.

cynthia
LAtwood
Calcite | Level 5
Cynthia,

The data is all in one table. And Yes I would like to "stack" the headers and data values by employee.
I would also like the output to be PDF.

Please let me know if I can provide more information to be helpful.

Thanks
Cynthia_sas
SAS Super FREQ
Hi:
By far, the easiest thing to do would be to use BY group processing to print 1 observation per employee, wrapped across multiple rows. This doesn't exactly give you the look you want, but it does get one employee's observation as a "unit". With ODS PDF options, such as STARTPAGE=NO, you can put multiple employee observations on one page.

The example below shows that method (#1) using selected observations from SASHELP.CLASS.

Your other alternatives are more programming intensive and depending on your comfort level, may or may not be worth the effort.

Method 2: Pre-process the original data to concatenate the employee information with the financial information and put the appropriate "line feed" instruction between the two pieces of information so it is stacked in the cell as you want. Change the labels as needed for your stacked cells. Then use PROC PRINT or PROC REPORT to send this new version of the data to ODS PDF.

Method 3: Use a custom table template with a DATA _NULL_ program to write to ODS PDF. The PROC TEMPLATE syntax for table templates has a method by which you can stack multiple variables into one cells.

cynthia
[pre]
** Method 1 -- print one table per person;
** make some extra variables so there is something to wrap;
** around to the next row.;

ods listing close;

data class1;
set sashelp.class;
where age le 12;
array xx $9 xvar1-xvar20;
do i = 1 to 20 by 1;
xx(i) = cats(put(i,2.0),'--',substr(name,1,1),'--',put(i,2.0));
end;
run;

proc sort data=class1 out=class1;
by name;
run;

options leftmargin=.25in rightmargin=.25in topmargin=.25in
bottommargin=.25in orientation=portrait center;

ods pdf file='c:\temp\Method1.pdf' startpage=no notoc;

proc report data=class1 nowd
style(report)={outputwidth=7.5in} ;
by name;
column sex age height weight xvar:;
run;

ods _all_ close;
[/pre]
LAtwood
Calcite | Level 5
Cynthia,

Thanks so much for that information. In Method 2 you mentioned I can change the labels as need for the stacked cells. How can I do this? For example, the first column will be stacked with dept info / job class info. How do I change the column name to:
dept
job_class

Instead of just:
dept

I will be performing this in E.G.
Cynthia_sas
SAS Super FREQ
Hi:
Even in EG, you will need to submit code. I do not believe this will be a point and click effort.

You will need, in PROC REPORT (or PROC PRINT) to define a SPLIT character (such as '*' in my code) and then manually build the labels for the "new" concatenated column (as in 'Name*Sex' or 'Height*Weight'). The ODS ESCAPECHAR function {newline} is used with a declared escape character to insert a line feed between the 2 values that are being concatenated. Since you have to do all the work in the DATA step program to concatenate the values together (see how I make the NAME_SEX and HT_WT variables?), that's why I said the BY group approach was by far, the easiest (in my opinion).

cynthia
[pre]
** Method2: pre-process the data and add a line feed;
** for the values that will be "stacked";

data class2;
length name_sex ht_wt $25;
set sashelp.class;
where age le 12;
name_sex = catt(name,'~{newline 1}',sex);
ht_wt = catt(put(height,5.1),'~{newline 1}',put(weight,5.2));
run;

ods pdf file='c:\temp\method2.pdf' notoc;
ods escapechar = '~';

proc report data=class2 nowd split='*';
column name_sex age ht_wt;
define name_sex / display 'Name*Sex'
style(column)={just=l};
define age / display '*Age';
define ht_wt/display 'Height*Weight'
style(column)={just=r};
run;
ods _all_ close;
[/pre]
Ksharp
Super User

Or

proc report data=class2 nowd;

     column ( 'Name' name_sex) age ht_wt;

     define name_sex / display  'Sex'

         style(column)={just=l};

     define age / display '*Age';

     define ht_wt/display 'Height*Weight'

         style(column)={just=r};

  run;

Kshar

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2485 views
  • 0 likes
  • 3 in conversation