The SAS Output Delivery System and reporting techniques

how to right justify the number columns in excel using excel tagsets

Reply
Contributor
Posts: 35

how to right justify the number columns in excel using excel tagsets

I am having difficulties in right justify the numbers when I use excel tagests. The numeric column 'dischg' displays center-justified even when I added options of 'just=right'.

Here is my code:

ods tagsets.ExcelXp;
proc report data = final;
column hospital dischg;
define hospital /group;
define dischg /sum style={tagattr='format:#,##0' just=right};
run;

Can you help? Thanks!
SAS Super FREQ
Posts: 8,739

Re: how to right justify the number columns in excel using excel tagsets

Hi:
When I make some fake data and run a version of your code, the numeric variables are right justified by default (see #1) and even with STYLE overrides added, the numeric variables are still right justified (see #2).

The only thing I noted was that the STYLE= override in your original code did not have the area in parentheses -- for PROC REPORT the form of the style overrride is generally:
[pre]
style(header)={....}
style(column)={....}
[/pre]

while for PROC TABULATE, the syntax is:
[pre]
style={....} or
*{s={....}} (in a TABLE statement)
[/pre]

Sometimes you can use the syntax without an area with REPORT and get OK results. But it's better to use the correct syntax so REPORT knows exactly which report element you want to change -- since the DEFINE statement could "touch" either the header cell or the data cells in the columns.

cynthia
[pre]
data final;
set sashelp.prdsale;
if country = 'GERMANY' then hospital = 'HS-1';
else if country = 'CANADA' then hospital = 'HS-2';
else hospital = 'HS-3';
dischg = int(actual /100);
othervar = int(actual);
run;

ods tagsets.ExcelXp file='c:\temp\dischg.xls' style=sasweb
options(embedded_titles='yes');

proc report data=final nowd;
title '1) default justification';
title2 'Left for CHAR var';
title3 'Right for NUM vars';
column hospital dischg othervar;
define hospital / group;
define dischg / sum;
define othervar / sum;
run;

proc report data=final nowd
style(column)={cellwidth=1in};
title '2) chg just for CHAR var';
title2 'right just for NUM vars';
title3 'bigger cells show just';
column hospital dischg othervar;
define hospital /group style(column)={just=c};
define dischg /sum style(column)={tagattr='format:#,##0' just=right};
define othervar / sum style(column)={foreground=red};
run;
ods tagsets.excelxp close;

[/pre]
Contributor
Posts: 35

Re: how to right justify the number columns in excel using excel tagsets

Thank you very much, Cynthia, for your help! I got it right now.
Ask a Question
Discussion stats
  • 2 replies
  • 472 views
  • 0 likes
  • 2 in conversation