Renamin variables produced with Proc freq

Reply
Occasional Contributor
Posts: 12

Renamin variables produced with Proc freq

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!

Occasional Contributor
Posts: 12

Re: Renamin variables produced with Proc freq

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!

Super User
Posts: 19,768

Re: Renamin variables produced with Proc freq

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

data want;

set have;

rename old_name=new_name;

run;

Occasional Contributor
Posts: 12

Re: Renamin variables produced with Proc freq

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

Super User
Posts: 19,768

Re: Renamin variables produced with Proc freq

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
Occasional Contributor
Posts: 12

Re: Renamin variables produced with Proc freq

Thank you for your help it worked!

Ask a Question
Discussion stats
  • 5 replies
  • 225 views
  • 0 likes
  • 2 in conversation