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;
Hi, Andre:
JUSTIFY= may not be in the tip sheets, but it is in the documentation for PROC TEMPLATE, the DEFINE COLUMN doc:
I think the tip sheets are good, but not a replacement for the full doc.
cynthia
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
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
Hi, Andre:
JUSTIFY= may not be in the tip sheets, but it is in the documentation for PROC TEMPLATE, the DEFINE COLUMN doc:
I think the tip sheets are good, but not a replacement for the full doc.
cynthia
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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.