The SAS Output Delivery System and reporting techniques

More variables stacked in one cell in PROC REPORT

Reply
SAS Employee
Posts: 11

More variables stacked in one cell in PROC REPORT

Hi Friends,

I would like to have two variables, Name and IDNumber stacked one on the top of the other in the same cell using ODS PDF and PROC REPORT.
I got this using PROC TEMPLATE, ODS PDF and a data step in which I build a concatenated variable made of Name and IDNumber variables, but is it possible to have this using PROC TEMPLATE instaed of the DATA _NULL_ step?

Thanks a lot!
Cheers
Michela



Example :






123456

Name
dd.mm.yyyy
10 000,00
10 000,00
123456

Name
dd.mm.yyyy
10 000,00
10 000,00
123456

Name
dd.mm.yyyy
10 000,00
10 000,00
123456

Name
dd.mm.yyyy
10 000,00
10 000,00


SAS Super FREQ
Posts: 8,868

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Michela_sas
Hi:
I'm not exactly sure what is wanted. Here's some code that stacks name and age from SASHELP.CLASS in one cell, using PROC REPORT: [pre]
ods listing close;

ods pdf file='stack_col.pdf';
ods escapechar='~';
proc report data=newclass nowd;
column name age newvar height;
define name /order noprint;
define age /display noprint;
define newvar / computed;
define height /display
style(column)={vjust=b};
compute newvar;
newvar = name||"~n"||put(age,3.0);
endcomp;
run;
ods pdf close;[/pre]

Note how the concatenated variable is built inside the PROC REPORT syntax with a COMPUTE block. You could have done this concatenation in a data step before the PROC REPORT step -- but the COMPUTE block works very nicely. The only thing you have to be careful about is that the variables that you will concatenate together must appear in the COLUMN statement before the computed variable. In order for this to work, you also must use ODS ESCAPECHAR (in this case, a tilde (~) so that you can put a "line break" in between the two variables.

What is at the bottom of your note is HTML, which is why I'm confused about what it is you want. When you say that you want to use PROC TEMPLATE instead of the DATA _NULL_ , I'm not sure if you want PROC TEMPLATE for a table template associated with a procedure (like PROC MEANS). A style template won't do what you want and a tagset template might allow you to stack variables in a cell or change HTML or other MARKUP, but PDF is not a markup destination.

Yes, it is possible to stack columns inside a TABLE template associated with a procedure. In that instance, you would change the TABLE template, put the TABLE template in an item store like SASUSER.TEMPLAT. Then the next time you use the procedure, if your ODS PATH is pointing to the item store, the procedure would use the changed TABLE template.

It seems to me that PROC REPORT will do what you want.
cynthia
SAS Employee
Posts: 11

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Cynthia_sas
Thank you Cynthia!

What I want is to have a table created using PROC REPORT and ODS PDF, in which the first columns has cells with two stacked variables.
I think that the trick to use the compute as you described could solve my case.

I tried to run the code you wrote below using sashelp.class to see if the result was simila to what I need, but I got a lot of errors like:
NOTE: Character values have been converted to numeric values at the places given by:
(Line)Smiley SadColumn).
1:21
NOTE: Invalid numeric data, 'Alfred ~n 14' , at line 1 column 21.
NOTE: Invalid numeric data, 'Alice ~n 13' , at line 1 column 21.
etc...

What did I do wrong?

Thanks!
Michela
SAS Super FREQ
Posts: 8,868

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Michela_sas
So sorry, my bad. By default, the variable created in a compute block is assumed to be numeric. You need to tell the compute block that it is a character variable. I was typing too fast.[pre]
proc report data=sashelp.class nowd;
.... more code ....;
compute newvar / character length=40;
newvar = name||"~n"||put(age,3.0);
endcomp;
run;
[/pre]

cynthia
SAS Employee
Posts: 11

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Cynthia_sas
Sorry, my apologies for getting back to you again, but still I can't make it to work.
The ~n is not resolved correctly ( it appears as it is) and the age field is not concatenated, despite changing the size of the character string from 40 to something like 20, 25 etc...

Thanks again!
Michela
SAS Super FREQ
Posts: 8,868

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Michela_sas
Hi:
you need to be sure to set the ODS ESCAPECHAR = '~'; statement as shown below:

[pre]
ods listing close;
ods pdf file='stack_col.pdf';
ods escapechar='~';
proc report data=sashelp.class nowd;
column name age newvar height;
define name /order noprint;
define age /display noprint;
define newvar / computed;
define height /display
style(column)={vjust=b};
compute newvar / character length=40;
newvar = name||"~n"||put(age,3.0);
endcomp;
run;
ods pdf close;
[/pre]

This will ONLY work in the PDF file that's created. You will see the ~n in the LISTING output. The ODS Escapechar facillity started working in SAS 8.2 -- if this technique is not working for you -- in the PDF file, your best bet is to contact SAS Technical Support for help.

Good luck,
cynthia
SAS Employee
Posts: 11

Re: More variables stacked in one cell in PROC REPORT

Posted in reply to Michela_sas
Thank you very much, it works perfectly now!

Kind regards.
Michela
Ask a Question
Discussion stats
  • 6 replies
  • 160 views
  • 0 likes
  • 2 in conversation