The SAS Output Delivery System and reporting techniques

PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Dear all,

I tried to produce a table in RTF using PROC TEMPLATE and I'm currently struggling with the alignment of the values in columns.

My test data set has character and numeric variables.

When I run the program with the default settings (without the JUST= ), I get the character values aligned LEFT and numeric RIGHT.

Then I played a bit with the JUST= option to change the alignment. First, I switched the character columns to RIGHT and numeric to LEFT and it worked fine. But when I did set all columns to JUST=CENTER, then I got the character columns centered, but NOT the numeric column.

Does anyone have an idea, why it did not work with the numeric column? What is the difference?

Thank you in advance!

Please find below the complete code of the table definition and my test data set:

*PROC TEMPLATE for TABLE*;

PROC TEMPLATE;

   DEFINE TABLE MyTABLE;

      COLUMN      NAME AGE ;

      DYNAMIC     COLHEADER;

      DEFINE NAME;

         GENERIC  =  ON;

         HEADER   =  COLHEADER;

         JUST     =  CENTER;

      END;

      DEFINE AGE;

         GENERIC  =  ON;

         HEADER   =  COLHEADER;

         JUST     =  CENTER;

         STYLE    =  DATA {WIDTH    =  25mm};

      END;

   END;

RUN;

*Data set with test data*;

DATA newGirl;

   ATTRIB   FNAME  FORMAT=$25.         LABEL="First name"

            LNAME  FORMAT=$25.         LABEL="Last name"

            NNAME  FORMAT=$25.         LABEL="Nickname"

            AGE    FORMAT=5.2          LABEL="Age"

            ;

   FNAME="Jessica";      LNAME="Day";            NNAME="Jess";      AGE=30.3;       OUTPUT;

   FNAME="";             LNAME="Schmidt ";       NNAME="Schmid";    AGE=29.22;      OUTPUT;

   FNAME="Nickolas";     LNAME="Miller";         NNAME="Nick";      AGE=32.1;       OUTPUT;

   FNAME=" ";            LNAME="Winston";        NNAME="Winston";   AGE=32.4569;    OUTPUT;

   FNAME=" ";            LNAME="Cecelia";        NNAME="Cece";      AGE=28.7;       OUTPUT;

RUN;

ODS LISTING CLOSE;

OPTIONS NODATE NONUMBER;

TITLE;

FOOTNOTE;

OPTIONS ORIENTATION=PORTRAIT;

ODS RTF FILE="C:\Test.rtf" ;

DATA _NULL_;

   SET newGirl;

   FILE PRINT ODS=(TEMPLATE="MyTABLE"

                   COLUMNS=(name=fname  (GENERIC = ON

                                         DYNAMIC  = (COLHEADER="First name"))

                            name=lname  (GENERIC = ON

                                         DYNAMIC = (COLHEADER="Last name"))

                            name=nname  (GENERIC = ON

                                         DYNAMIC =(COLHEADER="Nickname"))

                            age=age    (GENERIC = ON

                                        DYNAMIC =(COLHEADER="Age"))

                            )

                     );

   PUT _ODS_;

RUN;

ODS RTF CLOSE;


Accepted Solutions
Solution
‎05-21-2012 05:29 PM
SAS Super FREQ
Posts: 8,743

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Hi, Andre:

  JUSTIFY= may not be in the tip sheets, but it is in the documentation for PROC TEMPLATE, the DEFINE COLUMN doc:

http://support.sas.com/documentation/cdl/en/odsug/62755/HTML/default/viewer.htm#n0bmbi5i2bo1p1n1okcg...

  I think the tip sheets are good, but not a replacement for the full doc.

cynthia

View solution in original post


All Replies
Super Contributor
Posts: 273

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

it is possible  following another way end of your code (same template)

ODS LISTING CLOSE;

*ods html close;

OPTIONS NODATE NONUMBER;

TITLE;

FOOTNOTE;

OPTIONS ORIENTATION=PORTRAIT;

ODS RTF FILE="d:\temp\centerTest.rtf" ;

DATA _NULL_;

   SET newGirl; format age best12.;

   FILE PRINT ODS=(TEMPLATE="MyTABLE"

COLUMNS=(name=fname  (GENERIC = ON

DYNAMIC  = (COLHEADER="First name"))

                            name=lname  (GENERIC = ON

DYNAMIC = (COLHEADER="Last name"))

                            name=nname  (GENERIC = ON

DYNAMIC =(COLHEADER="Nickname"))

                            age=age    (GENERIC = ON

                                        DYNAMIC =(COLHEADER="Age"))

                            )

);

   PUT _ODS_;

RUN;

proc print data=newgirl noobs label Style(table)={ cellpadding=10 cellspacing=0 mm}

                          style(header)={just=c};

var fname /style={just=c};

var lname /style={just=c};

var nname/style={just=c};

var age/style={just=d width=1.0in rightmargin=.25in};

run;

ODS RTF CLOSE;

ods listing;


Now my comment upon justifying a numeric column:

the amount that could appear for a numeric value can vary a lot

and at start the procedure has not idea at all how to center a unknown future value

numeric with decimal  comming from data

with proc print although it is possible


Andre


But impossible through template only    perhaps not  if you follow the rules that are presented in

http://support.sas.com/rnd/base/ods/scratch/styles-tips.pdf

much more difficult indeed

Andre

SAS Super FREQ
Posts: 8,743

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Hi:

  Once you learn how the JUSTIFY= option works, it's not so hard. The default behavior of TABLE templates is to "pad" with spaces to the formatted width. So you need to know this in order to tell the TABLE template whether to honor the format's padding (basically ignore the justification) or honor the justification (ignore the padding). JUSTIFY=OFF is the default (which says to honor the format's padding) while JUSTIFY=ON says to honor the justification and ignore the padding. So I believe that if you add JUSTIFY=ON; to your DEFINE blocks inside the TABLE template, you will get centered values. Of course, this is going to look better with integer numbers and/or numbers with the same amount of decimal places.

cynthia

Super Contributor
Posts: 273

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Thanks Cynthia

i was not aware of  this interaction between template justify/padding and the general template justify= order

this is not mentionned on the style or table template sheets.

but my practise of table template is too rare

and

of course it exists since a long time

Andre

Solution
‎05-21-2012 05:29 PM
SAS Super FREQ
Posts: 8,743

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Hi, Andre:

  JUSTIFY= may not be in the tip sheets, but it is in the documentation for PROC TEMPLATE, the DEFINE COLUMN doc:

http://support.sas.com/documentation/cdl/en/odsug/62755/HTML/default/viewer.htm#n0bmbi5i2bo1p1n1okcg...

  I think the tip sheets are good, but not a replacement for the full doc.

cynthia

Contributor
Posts: 28

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Hi Synthia,

Thank you!

I added the JUSTIFY=ON and now the values are centred.

Yes, I agree, with the same amount of the decimal places it looks better. 

Natalie

Contributor
Posts: 28

Re: PROC TEMPLATE and JUST=CENTER does not work with numeric variables?

Hi Andre,

I haven't used PROC PRINT yet to create the table in RTF, will have a look at it now, thank you for the tip.

Natalie

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1678 views
  • 0 likes
  • 3 in conversation