Solved
Contributor
Posts: 53

# Aligning text print output in statistical table

Hi,

I am trying to produce a table of mean abnormal returns where each mean has an associated p-value. Instead of printing two columns, one for the mean and the other for the p-value, I just want to add stars to the mean estimate to indicate the level of significance where H0=0 (a "classical" table of statistics).

What I am getting is output similar to col2 below, but I want to get is col3 where the juncture between the number and the stars for each observation line up. How can I do this?

evttimear1_txtar1_txt (DESIRED)
-300.0101 **0.0101**
-29-0.0211-0.0211
-28-0.1112 *-0.1112*
-270.01130.0113
-26-0.0001 ***-0.0001***

* = p<.1  ; ** = p<.05  ; *** = p<.01

The exact code that I am using and output is below. ar1m is a mean estimation of the abnormal return and pat_ar1_p is the p-value. How can I change the code to get the desired output?

data pres_tb (keep=evttime ar1_txt);

set mm_evtwin;

if pat_ar1_p<.01  then ar1_txt=cat( put(ar1m,7.4), ' *** ');

else if pat_ar1_p<.05 then ar1_txt=cat( put(ar1m,7.4), ' **  ');

else if pat_ar1_p<.1  then ar1_txt=cat( put(ar1m,7.4), ' *   ');

else   ar1_txt=cat( put(ar1m,7.4), '     ');

if abret1_mean>0 then ar1_txt=cat( '    ', ar1_txt );

run;

proc print data=pres_tb noobs label;

var evttime / style={textalign=center font_weight=bold};

var ar1_txt;

run;

The exact output I get is this where the negative signs:

 -30 -0.0331 -29 0.0097 -28 0.0036 -27 -0.0704 ** -26 -0.0568 -25 0.0417 -24 -0.0167 -23 0.0091 * -22 -0.0078 -21 -0.0197 -20 -0.0711 ** -19 -0.0757 -18 0.0750

Thanks,

Ian.

Accepted Solutions
Solution
‎11-29-2012 08:25 PM
SAS Super FREQ
Posts: 9,365

## Re: Aligning text print output in statistical table

Hi:

I think that JUST=D will work for ODS PDF.  Since AR1_TXT has the **, you can use a STYLE= override. But I think that JUST=D will only work for ODS PDF or RTF -- not HTML.

cynthia

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

proc print data=pres_tb noobs label;

var evttime / style={textalign=center font_weight=bold};

var ar1_txt / style={just=d};

run;

ods _all_ close;

All Replies
Super User
Posts: 23,662

## Re: Aligning text print output in statistical table

The following works for me. You may want to double check your boundary conditions, ie should it be < or <=?

Note how the space is added in as a leading blank for numbers with a mean > 0.

It may or may not work depending on your output destination which you haven't specified.

data have;

input evttime mean p_value;

cards;

-30    -0.0331 0.23

-29    0.0097 0.23

-28    0.0036 0.23

-27    -0.0704 0.03

-26    -0.0568 0.01

-25    0.0417 0.001

-24    -0.0167 0.001

-23    0.0091 0.23

-22    -0.0078 0.014

-21    -0.0197 0.05

-20    -0.0711 0.04

-19    -0.0757 0.01

-18    0.0750 0.45

;

run;

data pres_tb;

set have;

length ar1_txt \$15.;

format ar1_txt \$char15.;

if p_value<.01  then ar1_txt=catx( "",put(mean,7.4), '***');

else if p_value<.05 then ar1_txt=catx( "", put(mean,7.4), '**');

else if p_value<.1  then ar1_txt=catx( "", put(mean,7.4), '*');

else  ar1_txt=catx("", put(mean,7.4), '   ');

if mean > 0 then ar1_txt=" "||trim(ar1_txt);*The space in this line is achieved by type ALT+255 on the keyboard instead of a space using the spacebar;

run;

Contributor
Posts: 53

## Re: Aligning text print output in statistical table

Reeza,

Thanks very much for writing the code and also the headsup on the boundary conditions.

Using your code, I am able to get the table, when seen in the VIEWTABLE screen, to look the way I want. However, the problem is when using PROC PRINT, all the work of adding leading spaces comes undone. What code can I use to make the data come out "lined up correctly"?

Thanks again for your time!

Ian.

Super User
Posts: 23,662

## Re: Aligning text print output in statistical table

What destination are you outputting to?

RTF, PDF, Excel, HTML?

It come up fine in the listing for me, but I haven't tried other destinations.

Contributor
Posts: 53

## Re: Aligning text print output in statistical table

I am outputting to HTML and PDF. Both destinations have misaligned listings.

If possible, I would like to align the list on the vertical axis that can be drawn between the last digit of the mean and the first star.

Thanks again.

Ian.

Solution
‎11-29-2012 08:25 PM
SAS Super FREQ
Posts: 9,365

## Re: Aligning text print output in statistical table

Hi:

I think that JUST=D will work for ODS PDF.  Since AR1_TXT has the **, you can use a STYLE= override. But I think that JUST=D will only work for ODS PDF or RTF -- not HTML.

cynthia

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

proc print data=pres_tb noobs label;

var evttime / style={textalign=center font_weight=bold};

var ar1_txt / style={just=d};

run;

ods _all_ close;

Contributor
Posts: 53

## Re: Aligning text print output in statistical table

Posted in reply to Cynthia_sas

Thanks you Cynthia. It works with both ODS PDF and RTF, and not HTML as you said.

Super User
Posts: 10,761

## Re: Aligning text print output in statistical table

You can use escape character to instead of a blank.

data have;

input evttime mean p_value;

cards;

-30    -0.0331 0.23

-29    0.0097 0.23

-28    0.0036 0.23

-27    -0.0704 0.03

-26    -0.0568 0.01

-25    0.0417 0.001

-24    -0.0167 0.001

-23    0.0091 0.23

-22    -0.0078 0.014

-21    -0.0197 0.05

-20    -0.0711 0.04

-19    -0.0757 0.01

-18    0.0750 0.45

;

run;

data pres_tb;

set have;

length ar1_txt \$15.;

format ar1_txt \$char15.;

if p_value<.01  then ar1_txt=catx( "",put(mean,7.4), '***');

else if p_value<.05 then ar1_txt=catx( "", put(mean,7.4), '**');

else if p_value<.1  then ar1_txt=catx( "", put(mean,7.4), '*');

else  ar1_txt=catx("", put(mean,7.4), '   ');

if mean > 0 then ar1_txt="~_"||trim(ar1_txt);*The space in this line is achieved by type ALT+255 on the keyboard instead of a space using the spacebar;

run;

ods html file='c:\temp\lineup.htm';

ods escapechar='~';

proc print data=pres_tb noobs label;

var evttime / style={textalign=center font_weight=bold};

var ar1_txt / style={just=l};

run;

ods html close;

Ksharp

Contributor
Posts: 53

## Re: Aligning text print output in statistical table

Thank you very much Ksharp. A very helpful answer! Now I am able to get ODS output in PDF, RTF, and HTML.

Ian.

🔒 This topic is solved and locked.

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

Discussion stats
• 8 replies
• 459 views
• 9 likes
• 4 in conversation