How to calculate P Value in SAS

Reply
Occasional Contributor
Posts: 11

How to calculate P Value in SAS

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

Super Contributor
Posts: 280

Re: How to calculate P Value in SAS

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

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

Hi Jacob,

I am using Chi Square test for this.

Regards,

Ratan

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

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

Super Contributor
Posts: 280

Re: How to calculate P Value in SAS

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;

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

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

Grand Advisor
Posts: 9,596

Re: How to calculate P Value in SAS

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

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

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

Super Contributor
Posts: 280

Re: How to calculate P Value in SAS

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

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

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

Super Contributor
Posts: 280

Re: How to calculate P Value in SAS

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

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

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

Grand Advisor
Posts: 9,596

Re: How to calculate P Value in SAS

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

Occasional Contributor
Posts: 11

Re: How to calculate P Value in SAS

Hi Keshan,

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

Regards,

Ratan

Grand Advisor
Posts: 9,596

Re: How to calculate P Value in SAS

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

Ask a Question
Discussion stats
  • 21 replies
  • 9279 views
  • 7 likes
  • 4 in conversation