turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How to calculate P Value in SAS

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2014 01:20 PM

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

Accepted Solutions

Solution

10-24-2017
08:35 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

08-31-2014 02:27 PM - last edited on 10-24-2017 08:34 AM by ChrisHemedinger

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

All Replies

Solution

10-24-2017
08:35 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

08-31-2014 02:27 PM - last edited on 10-24-2017 08:34 AM by ChrisHemedinger

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JacobSimonsen

09-01-2014 02:50 AM

Hi Jacob,

I am using Chi Square test for this.

Regards,

Ratan

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JacobSimonsen

09-01-2014 05:19 AM

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;

Please help and suggest me on this.

Regards,

Ratan

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 05:35 AM

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JacobSimonsen

09-01-2014 07:17 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 08:17 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

09-01-2014 09:04 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 07:55 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JacobSimonsen

09-01-2014 08:20 AM

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?

Regards,

Ratan

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 08:27 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JacobSimonsen

09-01-2014 08:55 AM

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.

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 09:01 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

09-01-2014 09:08 AM

Hi Keshan,

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

Regards,

Ratan

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ratanroy

09-01-2014 09:16 AM

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