BookmarkSubscribeRSS Feed
Michela_sas
SAS Employee
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


6 REPLIES 6
Cynthia_sas
SAS Super FREQ
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
Michela_sas
SAS Employee
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):(Column).
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
Cynthia_sas
SAS Super FREQ
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
Michela_sas
SAS Employee
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
Cynthia_sas
SAS Super FREQ
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
Michela_sas
SAS Employee
Thank you very much, it works perfectly now!

Kind regards.
Michela

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
  • 1574 views
  • 0 likes
  • 2 in conversation