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

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
-290.0097
-280.0036
-27-0.0704 **
-26-0.0568
-250.0417
-24-0.0167
-230.0091 *
-22-0.0078
-21-0.0197
-20-0.0711 **
-19-0.0757
-180.0750

Thanks,

Ian.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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;


just_d_pdf.png

View solution in original post

8 REPLIES 8
Reeza
Super User

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;

iank131
Quartz | Level 8

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.

Reeza
Super User

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.

iank131
Quartz | Level 8

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.

Cynthia_sas
SAS Super FREQ

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;


just_d_pdf.png
iank131
Quartz | Level 8

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

Ksharp
Super User

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

iank131
Quartz | Level 8

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

Ian.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 1646 views
  • 9 likes
  • 4 in conversation