I have a vector that contains many estimates and their t-stats below each estimate as follows.
0.04 - estimate
5.36 - t-stat
2.45 - estimate
1.99 - t-stat
0.12 - estimate
4.87 - t-stat
-4.64 - estimate
-0.23 - t-stat
-0.07 - estimate
-5.23 - t-stat
...
1. Though IML provides PRINT, the numbers in printed vectors must share identical formats. What should I do if I want to put parentheses for the t-stats but just leave the estimates? For example,
0.04
(5.36)
2.45
(1.99)
...
2. There is a format for P-values in SAS, but is there any format that puts outer parentheses for observations in a DATA step?
@Junyong wrote:
Thanks for this answer, but still wonder whether one column can vertically display them as follows.
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
I wonder whether this can be done automatically. If not, I would probably try it manually as follows.
Thanks.
I am not aware of a SAS approach that will display columns of values from the same variable/ statistic that will allow different formats.
If ALL of your statistic values were completely outside the range of ALL of the estimates a format could be made to work but your initial post makes me believe that is very likely to apply.
If absolutely NONE of your statistic values are the same as ANY estimate you could make a custom format for those specific values with a CNTLIN data set which would be somewhat similar to your display data set.
That would be something like:
data have; do i=1 to 10; column1=rannor(1); output; end; drop i; run; data work.mycntlin; set have; fmtname='Myfmt'; type='N'; start=column1; if mod(_n_,2) then label=strip(put(column1,8.3)); else label="("||strip(put(column1,6.3))||")"; drop column1; run; proc format library=work cntlin=work.mycntlin; run; proc print data=have; var column1; format column1 myfmt.; run;
However, you would 1) need to do this for every single data set ever 2) expect it to fail constantly as it is extremely likely that the more values involved the more likely one of your estimates will be the same as the statistic (isn't the purpose of an estimate to hopefully model the statistic with the goal of being identical????) . Proc Format in any case would never allow the same value to be displayed differently.
Proc format library=work; value badformat 1 = '1' 1 = '(1)' ; run;
Will generate:
62 Proc format library=work; 63 value badformat 64 1 = '1' 65 1 = '(1)' ERROR: This range is repeated, or values overlap: 1-1. 66 ; NOTE: The previous statement has been deleted. 67 run;
because any value can be assigned one and only one display value with a format.
Maybe time to leave IML and transpose the data so you have two columns of values, one of estimates and one of stats. Then Proc print and a trivial issue.
Easy enough to role your own format
proc format library=work; picture myparen low-high = '0009.99)' (prefix='(' ) ; run; data junk; input x; format x myparen.; datalines; 1 .1 10 2.09 3.3333 ;
Thanks for this answer, but still wonder whether one column can vertically display them as follows.
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
I wonder whether this can be done automatically. If not, I would probably try it manually as follows.
data have;
do i=1 to 10;
column1=rannor(1);
output;
end;
drop i;
run;
data display;
set have;
if mod(_n_,2) then model1=strip(put(column1,8.3));
else model1="("||strip(put(column1,6.3))||")";
drop column1;
run;
proc print noobs;
run;
Thanks.
@Junyong wrote:
Thanks for this answer, but still wonder whether one column can vertically display them as follows.
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
estimate | estimate | estimate
(t-stat) | (t-stat) | (t-stat)
I wonder whether this can be done automatically. If not, I would probably try it manually as follows.
Thanks.
I am not aware of a SAS approach that will display columns of values from the same variable/ statistic that will allow different formats.
If ALL of your statistic values were completely outside the range of ALL of the estimates a format could be made to work but your initial post makes me believe that is very likely to apply.
If absolutely NONE of your statistic values are the same as ANY estimate you could make a custom format for those specific values with a CNTLIN data set which would be somewhat similar to your display data set.
That would be something like:
data have; do i=1 to 10; column1=rannor(1); output; end; drop i; run; data work.mycntlin; set have; fmtname='Myfmt'; type='N'; start=column1; if mod(_n_,2) then label=strip(put(column1,8.3)); else label="("||strip(put(column1,6.3))||")"; drop column1; run; proc format library=work cntlin=work.mycntlin; run; proc print data=have; var column1; format column1 myfmt.; run;
However, you would 1) need to do this for every single data set ever 2) expect it to fail constantly as it is extremely likely that the more values involved the more likely one of your estimates will be the same as the statistic (isn't the purpose of an estimate to hopefully model the statistic with the goal of being identical????) . Proc Format in any case would never allow the same value to be displayed differently.
Proc format library=work; value badformat 1 = '1' 1 = '(1)' ; run;
Will generate:
62 Proc format library=work; 63 value badformat 64 1 = '1' 65 1 = '(1)' ERROR: This range is repeated, or values overlap: 1-1. 66 ; NOTE: The previous statement has been deleted. 67 run;
because any value can be assigned one and only one display value with a format.
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.