BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Natalie
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

6 REPLIES 6
Andre
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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

Andre
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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

Natalie
Calcite | Level 5

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

Natalie
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5813 views
  • 0 likes
  • 3 in conversation