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

Hello, SAS community!

 

I have a table with some daily data (Sample_data). 'Date' variable specifies the date. 'Group' denotes the assigned group for each value.

 

DateGroup 1Group 2Group 3Group 4
10/4/201912.0012.0012.0012.00
10/5/201912.0034.0034.0034.00
10/6/201912.0043.0043.0043.00
10/7/201912.0060.6760.6760.67
10/8/201932.0076.1776.1776.17
10/9/201943.0091.6791.6791.67
10/10/201940.49107.17107.17107.17
10/11/201946.35122.67122.67122.67
10/12/201952.22138.17138.17138.17

 

I would like to create another table with means and t-statistics in parentheses for each group (1 row, 4 columns) and add to the mean values in the new table stars as superscripts which will identify the significance level(e.g. ***, **, and * denotes significance level of 1%, 5% and 10%  respectively). 

 

I kindly ask SAS experts to help me with a code.

Best regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1. Use PROC MEANS to get the results needed in cells - T, PROBT and MEAN are the stats you want and PROC MEANS shows them

2. Use CATT() to combine into displayed values you want

3. Transpose to a wide format

 

Untested unfortunately, but should get you started. Note that the proc means creates two output data sets, summary1 and summary2 in different layouts. 

I felt the second is more dynamic. 

 

proc means data=have N MEAN T PROBT STACKODS;
var group1-group4;
output out=summary1 n= mean= t= probt= / autoname;
ods output summary=summary2;
run;

data want_long;
set summary2;
length asterisk $3.;
if probt<0.01 then asterisk ='***';
else if probt<0.05 then asterisk = "**";
else if probt<0.1 then asterisk='*';

display = catt(mean, "(", t, ")", asterisk);

run;

*not sure about this step, flip to wide format;
proc transpose data=want_long out=want_wide ;
id variable;
var display;
run;


@Astana wrote:

Hello, SAS community!

 

I have a table with some daily data (Sample_data). 'Date' variable specifies the date. 'Group' denotes the assigned group for each value.

 

Date Group 1 Group 2 Group 3 Group 4
10/4/2019 12.00 12.00 12.00 12.00
10/5/2019 12.00 34.00 34.00 34.00
10/6/2019 12.00 43.00 43.00 43.00
10/7/2019 12.00 60.67 60.67 60.67
10/8/2019 32.00 76.17 76.17 76.17
10/9/2019 43.00 91.67 91.67 91.67
10/10/2019 40.49 107.17 107.17 107.17
10/11/2019 46.35 122.67 122.67 122.67
10/12/2019 52.22 138.17 138.17 138.17

 

I would like to create another table with means and t-statistics in parentheses for each group (1 row, 4 columns) and add to the mean values in the new table stars as superscripts which will identify the significance level(e.g. ***, **, and * denotes significance level of 1%, 5% and 10%  respectively). 

 

I kindly ask SAS experts to help me with a code.

Best regards,


 

View solution in original post

10 REPLIES 10
Reeza
Super User
What tests determine the significance levels? Can you show the expected output based on this data?
Astana
Calcite | Level 5

Thank you, Reeza.

 

The significance level is determined by whether p-value is smaller then the specified significance level.

P-value is calculated from defining t-stat (mean/st.error) and degrees of freedom (# of observations - 1)

 

Here is the desired output (significance levels don't reflect the actual one)

 

 Group 1Group 2Group 3Group 4
Mean29.12(7.05)*76.17(11.69)**76.17(11.69)**76.17(11.69)**
Reeza
Super User
What is the t-test? Against the other groups? Against a known value? If you're testing against the other groups are you doing that one by one? If so, are you correcting for multiple testing?

Astana
Calcite | Level 5

T-stat for the group we calculate using the mean of the same group and divide by st.error of the same group.

Degrees of freedom are calculated by subtracting 1 from the number of observations in the group.

 

Using t-stat and degrees of freedom as inputs we can calculate the p-value.

Excel formula for this is T.DIST.RT(tstat, df)

 

Comparing p value with significance level (0.01, 0.05, 0.10) we can conclude whether the mean value is different from zero.

Example: if we find p-value equal to 0.08 then mean value is different from zero with 0.10 significance level. So we assign one asterisk.

so the result will be: mean_value(t_stat)*

Reeza
Super User
So you're testing if the mean values are different than 0?
Astana
Calcite | Level 5

Yes. This is what I am trying to get.

Reeza
Super User

1. Use PROC MEANS to get the results needed in cells - T, PROBT and MEAN are the stats you want and PROC MEANS shows them

2. Use CATT() to combine into displayed values you want

3. Transpose to a wide format

 

Untested unfortunately, but should get you started. Note that the proc means creates two output data sets, summary1 and summary2 in different layouts. 

I felt the second is more dynamic. 

 

proc means data=have N MEAN T PROBT STACKODS;
var group1-group4;
output out=summary1 n= mean= t= probt= / autoname;
ods output summary=summary2;
run;

data want_long;
set summary2;
length asterisk $3.;
if probt<0.01 then asterisk ='***';
else if probt<0.05 then asterisk = "**";
else if probt<0.1 then asterisk='*';

display = catt(mean, "(", t, ")", asterisk);

run;

*not sure about this step, flip to wide format;
proc transpose data=want_long out=want_wide ;
id variable;
var display;
run;


@Astana wrote:

Hello, SAS community!

 

I have a table with some daily data (Sample_data). 'Date' variable specifies the date. 'Group' denotes the assigned group for each value.

 

Date Group 1 Group 2 Group 3 Group 4
10/4/2019 12.00 12.00 12.00 12.00
10/5/2019 12.00 34.00 34.00 34.00
10/6/2019 12.00 43.00 43.00 43.00
10/7/2019 12.00 60.67 60.67 60.67
10/8/2019 32.00 76.17 76.17 76.17
10/9/2019 43.00 91.67 91.67 91.67
10/10/2019 40.49 107.17 107.17 107.17
10/11/2019 46.35 122.67 122.67 122.67
10/12/2019 52.22 138.17 138.17 138.17

 

I would like to create another table with means and t-statistics in parentheses for each group (1 row, 4 columns) and add to the mean values in the new table stars as superscripts which will identify the significance level(e.g. ***, **, and * denotes significance level of 1%, 5% and 10%  respectively). 

 

I kindly ask SAS experts to help me with a code.

Best regards,


 

Astana
Calcite | Level 5

Thank you! That works perfectly!

Is there any mean I can make the final output values rounded to 4-5 values after the decimal point?

Reeza
Super User
Replace mean with put(mean, 12.4) in the CATT function.
Astana
Calcite | Level 5
Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 3053 views
  • 0 likes
  • 2 in conversation