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

Hi All,

could you please tell me how would i calculate p-value in SAS ? is there any direct formula for this?

suppose i have four columns :

Age    Satisfaction Rate         Recommended               Pain

45      Stongly Agree(5)         Stongly Agree(5)                    1

40     Agree(4)                       Disagree(3)                           5

46     Disagree(3)                   Disagree(3)                           4

47    strongly Disagree(1)        Stongly Agree(5)                   3

28    Stongly Agree(5)            Stongly Agree(5 )                   4

please help me to calculate P-value for each fields Age, Satisfaction rate, Recommended and Pain.

Regards,

Ratan

1 ACCEPTED SOLUTION

Accepted Solutions
JacobSimonsen
Barite | Level 11

Dear Ratan,

 

You have to give some more information. To calculate a p-value we need to know what statistical hypothesis you want to test, and what test you want to use.

 

Jacob

 

Editor's note: this is a popular topic, so we've included some helpful resources here.

 

@Reeza reminds us that that you first need a hypothesis, and then you can determine the proper test.

A best practice for statistical analysis is first determine what type of test you need based on your hypothesis and then figure out how to do it in whatever application you have, SAS, R, SPSS.

Step 1. What is your hypothesis?

Step 2. What type of data do you have?

Step 3. What type of statistical tests are available/appropriate?

 

For this data and the stated goal, @Ksharp suggests PROC FREQ with Fisher's EXACT test.  See guidance in this blog post: Exact tests in PROC FREQ: What, when, and how

 

Another useful post for beginners: Summary statistics and t tests in SAS

 

View solution in original post

21 REPLIES 21
JacobSimonsen
Barite | Level 11

Dear Ratan,

 

You have to give some more information. To calculate a p-value we need to know what statistical hypothesis you want to test, and what test you want to use.

 

Jacob

 

Editor's note: this is a popular topic, so we've included some helpful resources here.

 

@Reeza reminds us that that you first need a hypothesis, and then you can determine the proper test.

A best practice for statistical analysis is first determine what type of test you need based on your hypothesis and then figure out how to do it in whatever application you have, SAS, R, SPSS.

Step 1. What is your hypothesis?

Step 2. What type of data do you have?

Step 3. What type of statistical tests are available/appropriate?

 

For this data and the stated goal, @Ksharp suggests PROC FREQ with Fisher's EXACT test.  See guidance in this blog post: Exact tests in PROC FREQ: What, when, and how

 

Another useful post for beginners: Summary statistics and t tests in SAS

 

Ratanroy
Calcite | Level 5

Hi Jacob,

I am using Chi Square test for this.

Regards,

Ratan

Ratanroy
Calcite | Level 5

Hi Jacob,

I have used used the below code for my data and i am getting the below result, its saying that chi square is not a valid test.

Proc freq data=indegene.sensorysuite;

tables (Age)*(Anxiety_before) / chisq

plots=(freqplot(twoway=grouphorizontal

scale=percent));

run;

Capture.JPG

Please help  and suggest me on this.

Regards,

Ratan

JacobSimonsen
Barite | Level 11

Dear Ratan,

It was not obviously from your original question that you wanted to test the hypothesis of no association between  the four collumns and some other variable which you did not mention. But now I understand your question:-)

What kind of variable is thes "anxiety_before" variable? If it is discrete with few distinct values (for example 'low', 'medium' and 'high') then you can test the hyphothises as in the program you wrote. If it is a contionous variable, what I think it is since the number of freedom (DF) is huge, then you can test the hyphotesis by assuming some distribution of the  "anxiety_before", for example normal distributed with different mean for different values of  "pain". This assumption should also be validated (use a qqplot). Then ANOVA analysis can be used,

proc glm data=indegene.sensorysuite;

  class pain;

model anxiety_before=pain/ss3;

run;

You can do the same for the other predictors. Though, age is reasonable a contionous variable, and therefore you can test association between age and anxiety_before by testing the slope=0 in a linear regression

proc glm data=indegene.sensorysuite;

model anxiety_before=age/ss3;

run;

Ratanroy
Calcite | Level 5

Hi Jacob,

anxiety_before is a ordinal variable. its nothing but the scale of 1-10 , 1 for lowest and 10 for maximum anxiety. I am attaching one dummy data for your reference.

Could you please help me to understand what code i have to use to find the p-value.

Regards,

Ratan

Ksharp
Super User

Your data is too sparse . use Fisher Exact Test.

proc freq data=sashelp.class;

table age*sex /fisher;

run;

proc freq data=sashelp.class;

table age*sex /chisq relrisk;

exact pchi or;

run;

Xia Keshan

Ratanroy
Calcite | Level 5

Hi Keshan,

Thank you for helping me on this. i have ordinal scale data here, so is it appropriate to use F-test? (Sorry I am new in this)

I have one new requirement which i have posted on the above and also attached the data. Could u pls help how would i accomplish this..?

Regards,

Ratan

JacobSimonsen
Barite | Level 11

Dear Ratan,

I see the problem, and I now also understand why you can not perform a chi^2 test. The chi-Square test will not Work since there are too many cells (number of different values of outcome times number of different values of the predictor). Also, even if it worked the chi-Square test is not efficient since it does not use that the outcome and predictors are ordinal.

A simple way to test association is the Spearman correlation. Here it is enough to have an ordinal scale since it is a rank test.

proc corr data=indegene.sensorysuite spearman;

var age anxiety_before;

run;

To do this you need to convert all you predictors to numerical values. It is not so important how you do this, if just the ordering is correct. This works because the Spearman correlation is only based on the ranks and not the values.

jacob

Ratanroy
Calcite | Level 5

Dear Jacob,

I have ran the code and i have got the below o/p. can u pls tell me which one is the P-value?

Capture.JPG

Regards,

Ratan

JacobSimonsen
Barite | Level 11

The number 0.1749 is test for correlation=0.

By the way, I aggre with Ksharp Ksharp that the data is too sparse to perform the chisq test, that was what I meant with "too many cells".

You should also try the exact test as he suggest, but be aware that the two test does not test the same hypothesis. Both test are meaning full. The Fisher's exact test does not assume an ordinal scale as the test for correlation does.

Jacob

Ratanroy
Calcite | Level 5

Hi Jacob,

Thanks for your suggestion.

I will use the suggested test and will let u know if i will have any query. I have one more query.

Capture.JPG

i have to show the result like this. i have two machine, Machine A is the old and Machine B is the new machine and whatever you are seeing in the screenshot is the count and i have to find out the P-value for this. I have understood for overall data how i have to calculate but in this how would i calculate the p-Value..?

I have attached the file for your reference.

Regards,

Ratan

Ksharp
Super User

You are calculating a spearman correlation coefficient , not a P-value . P-value is for a statistical test , you need a H0  as Jacob said .

You need firstly to know what statistical method I should use for these data .

Xia Keshan

Ratanroy
Calcite | Level 5

Hi Keshan,

could you please let me know in this scenario which method i need to use..?

Regards,

Ratan

Ksharp
Super User

If you are trying to do Chi-square Test ,then use my Fisher Exact Test code and that is going to be only one P-value for H0:  row variable and column variable are not correlated .

Xia Keshan

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
  • 21 replies
  • 54351 views
  • 7 likes
  • 4 in conversation