BookmarkSubscribeRSS Feed
kmorrowvt
Obsidian | Level 7

I'm trying to figure out how to center data in a column in proc report for ods pdf output and have the decimal points aligned.  I've been using just=d to align on decimals (which justifies to the right) but can't figure out how to also center the values.

This is what I'm getting:

Header

    17.5

      5.2

This is what I'm looking for:

Header

  17.5

    5.2

Any ideas?

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

Is this helpful?

proc template;

define style styles.center;

  parent=styles.printer;

  /* Control PROC PRINT's headers     */

   style header from header /

    cellwidth=1in

   just=c;

  /* Control PROC PRINT's data values */

   style data from data /

   just=d;

  /* Control the OBS column           */

   style rowheader from header /

    cellwidth=1in

    just=c;

end;

run;

kmorrowvt
Obsidian | Level 7

This doesn't seem to center the data.  The output is the same was using simply just=d.

Cynthia_sas
SAS Super FREQ

Hi:

  Inside PROC REPORT, you can also use JUST=C and JUST=D -- but no matter whether you're using PROC PRINT, PROC REPORT, PROC TABULATE or a custom TABLE template -- you can only have 1 justification value for your cells. 1cell=1justification

  But, if you look at the attached screenshot (red lines are my highlight), what you can do is approximate JUST=D and centered by fiddling with the right margin of the cell. You won't be able to have a "one size fits all" solution, because the width= and rightmargin= value may need to change for different data or even different fonts or font sizes, but this gets you closer to what you want. You might also play around with cellpadding to see whether that might look better. But cellpadding increases ALL the white space around your font characters whereas right margin just leaves white space on the right side of the cell/column.

cynthia

data class;

  set sashelp.class;

  height = height+.8;

  weight = weight+.9;

  if name in('Alfred' 'Carol' 'James')

     then do;

     height = 88.88;

     weight =77.77;

  end;

run;

   

ods listing close;

title; footnote;

ods pdf file='c:\temp\just_d.pdf';

  

proc report data=class nowd;

  column name age height weight weight=wt2;

  define height / 'ht Just=c'

         style(column)={just=c};

  define weight / 'wt just=d'

         style(column)={just=d};

  define wt2 / 'wt just=d/chg margin'

         style(column)={just=d width=1.0in rightmargin=.25in};

run;

ods _all_ close;


just_d_and_changed_margin.jpg
kmorrowvt
Obsidian | Level 7

This is great, thanks!

HTFlyer
Calcite | Level 5

Hey Cynthia, is there a similar work around for RTF, as the above code didn't work in RTF. Thanks.

Ksharp
Super User

A workaround is padding a character (i.e. 0) after decimal , and make it color as white.

Assuming there are only two digits after decimal.

 
data class;
  set sashelp.class;
  height = height+.8;
  weight = weight+.9;
  if name in('Alfred' 'Carol' 'James')
     then do;
     height = 88.88;
     weight =77.77;
  end;
 length char_weight $ 80;
 if mod(weight*10,1)=0 then char_weight=put(weight,best6.2)||'~S={foreground=white}0';
  else char_weight=put(weight,best6.2 );
run;
   
ods listing close;
title; footnote;
ods escapechar='~';
ods rtf file='c:\temp\just_d.rtf' style=journal;
  
proc report data=class nowd;
  column name age height weight char_weight;
  define height / 'ht Just=c'
         style(column)={just=c};
  define weight / 'wt just=d'
         style(column)={just=d};
  define char_weight / 'wt just=c with padding 0'
         style(column)={just=c width=2in asis=on};
run;
ods rtf close;
ods listing;

Xia Keshan

SmithCJGVSU
Obsidian | Level 7

@Cynthia_sas  What’s the best way to align percents/parenthesis if your data is character in the form, nn (pp.p%) or nn (pp)?

 

I started a new thread here, https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-TAGSETS-RTF-RTF-How-does-Decimal-Alignment....

 

I can’t seem to get just=d working how I’d like it to.  Particularly for proportional font like times new roman.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 23304 views
  • 6 likes
  • 6 in conversation