BookmarkSubscribeRSS Feed
Smithy
Calcite | Level 5

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.

diseasehabit
cancersmoking
cancerno smoking
no cancerno smoking
cancersmoking
cancersmoking
no cancersmoking
cancerno smoking
cancersmoking

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!

5 REPLIES 5
Smithy
Calcite | Level 5

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!

Reeza
Super User

Unless I'm missing something you can use any of the standard rename statements.

data want;

set have;

rename old_name=new_name;

run;

Smithy
Calcite | Level 5

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

Reeza
Super User

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

   #VariableTypeLenLabel

  15DF_CMHCONum 8DF for CMH Nonzero Correlation
  21DF_CMHGANum 8DF for CMH General Association
  18DF_CMHRMNum 8DF for CMH Row Mean Scores Differ
   6DF_LRCHINum 8DF for Likelihood Ratio Chi-Square
   9DF_MHCHINum 8DF for Mantel-Haenszel Chi-Square
   3DF_PCHINum 8DF for Chi-Square
   1N     Num 8Number of Subjects in the Stratum
  16P_CMHCORNum 8P-value for CMH Nonzero Correlation
  22P_CMHGANum 8P-value for CMH General Association
19P_CMHRMSNum 8P-value for CMH Row Mean Scores Differ
   7P_LRCHINum 8P-value for Likelihood Ratio Chi-Square
  10P_MHCHINum 8P-value for Mantel-Haenszel Chi-Square
   4P_PCHINum 8P-value for Chi-Square
  14_CMHCOR_Num 8CMH Nonzero Correlation
  20_CMHGA_Num 8CMH General Association
  17_CMHRMS_Num 8CMH Row Mean Scores Differ
  12_CONTGY_Num 8Contingency Coefficient
  13_CRAMV_Num 8Cramer's V
   5_LRCHI_Num 8Likelihood Ratio Chi-Square
   8_MHCHI_Num 8Mantel-Haenszel Chi-Square
   2_PCHI_Num 8Chi-Square
  11_PHI_ Num 8Phi Coefficient
Smithy
Calcite | Level 5

Thank you for your help it worked!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 735 views
  • 0 likes
  • 2 in conversation