08-03-2016 01:03 PM
If I have code that looks like this:
proc report data=work.test;
column dinner Year
define dinner / group f=$diner. ' ';
define year/across ' ' ;
and produce a report
2001 2002 2003
Tim's 90 1000 2312
Ferris' 19 20 89
I want to format the numbers to appear with commas, such as in the classics f=comma8. However, diner is a character variable, and unfortunately year is as well. Is there any way to apply number formats to counts of character variables, without having to convert the base variables to numeric?
08-03-2016 08:38 PM - edited 08-03-2016 08:40 PM
** make data into thousands; ** to use comma format; data heart; set sashelp.heart; output; output; run; proc report data=heart; column chol_status n,bp_status ; define chol_status / group; define bp_status / across; define n / 'Count' f=comma6.; run;
Yes, if you explicitly use the N statistic in the report, you can format the number. for example, see the results below.
08-04-2016 10:32 AM
08-04-2016 01:42 PM
If you do not need the Proc Report ability to calculate from other column results this may be possible with Proc Tabulate.
If I understand what you are attempting this may work:
proc tabulate data=work.test; class year dinner; format dinner $diner.; table dinner='', /* the ='' suppresses the variable or statistic label*/ year=''*n=''*f=comma8.
; /* the *f=comma8. says to apply the comma8. format to the n statistic*/ run;
There is also an option available that would put a column header in the empty box above the dinner variable. Amazingly that option is BOX and would go before the semicolon ending the TABLE statement. Somelike / BOX="some text"; The / is to indicate the start of table options. Or /Box=Dinner would place the label or variable name for dinner there.
08-04-2016 06:36 PM - edited 08-04-2016 06:40 PM
you can get rid of all those headers. Consider this change to the DEFINE statements:
define bp_status / ' ' across;
define n / ' ' f=comma6.;
That should leave you with just one column header row.
The above would work for HTML or RTF or PDF, but for EXCELXP or ODS EXCEL, you'd need to use TAGATTR to get the commas: