Two variables - disease and habit
Help me - calculate Cochran-Mantel-Haenzel, Chi-square and corresponding p-value. The output data set must have variables names: cmh_chi for Cochran-Mantel-Haenzel Chi-square and cmh_p for p value of Cochran-Mantel-Haenzel Chi-square.
disease | habit |
cancer | smoking |
cancer | no smoking |
no cancer | no smoking |
cancer | smoking |
cancer | smoking |
no cancer | smoking |
cancer | no smoking |
cancer | smoking |
I know how to use proc freq and how to calculate the mentioned statistics and create a new data set. What I dont know is how to rename the variables.
THANKS!
Data p1;
Set test."record$"n;
run;
proc freq data=p1;
tables disease*habit / cmh chisq;
output out=ChiSqData chisq pchi cmh;
title 'Chi-Square Tests for disease and habit';
run;
This is what I have so far help me modify it!
Unless I'm missing something you can use any of the standard rename statements.
data want;
set have;
rename old_name=new_name;
run;
I agree with you the problem is that I cant rename the variable if I dont have the name of it (old_variable) for some strange reason I cant find the correct number for the variables to be renamed. I go into the dataset but when I type what appears as the variable name it doesnt read it.
Thanks
run a proc contents on the data to see the valid name vs the label.
It looks like you want 8 & 10. If your code isn't work post the code and log.
Alphabetic List of Variables and Attributes |
# | Variable | Type | Len | Label |
15 | DF_CMHCO | Num | 8 | DF for CMH Nonzero Correlation |
21 | DF_CMHGA | Num | 8 | DF for CMH General Association |
18 | DF_CMHRM | Num | 8 | DF for CMH Row Mean Scores Differ |
6 | DF_LRCHI | Num | 8 | DF for Likelihood Ratio Chi-Square |
9 | DF_MHCHI | Num | 8 | DF for Mantel-Haenszel Chi-Square |
3 | DF_PCHI | Num | 8 | DF for Chi-Square |
1 | N | Num | 8 | Number of Subjects in the Stratum |
16 | P_CMHCOR | Num | 8 | P-value for CMH Nonzero Correlation |
22 | P_CMHGA | Num | 8 | P-value for CMH General Association |
19 | P_CMHRMS | Num | 8 | P-value for CMH Row Mean Scores Differ |
7 | P_LRCHI | Num | 8 | P-value for Likelihood Ratio Chi-Square |
10 | P_MHCHI | Num | 8 | P-value for Mantel-Haenszel Chi-Square |
4 | P_PCHI | Num | 8 | P-value for Chi-Square |
14 | _CMHCOR_ | Num | 8 | CMH Nonzero Correlation |
20 | _CMHGA_ | Num | 8 | CMH General Association |
17 | _CMHRMS_ | Num | 8 | CMH Row Mean Scores Differ |
12 | _CONTGY_ | Num | 8 | Contingency Coefficient |
13 | _CRAMV_ | Num | 8 | Cramer's V |
5 | _LRCHI_ | Num | 8 | Likelihood Ratio Chi-Square |
8 | _MHCHI_ | Num | 8 | Mantel-Haenszel Chi-Square |
2 | _PCHI_ | Num | 8 | Chi-Square |
11 | _PHI_ | Num | 8 | Phi Coefficient |
Thank you for your help it worked!
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.