The SAS Output Delivery System and reporting techniques

How to use Macro to ODS P-values from Wilcoxon Signed Rank Test

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to use Macro to ODS P-values from Wilcoxon Signed Rank Test

I just ran the Wilconxon signed rank test for 57 pairs of pretest and posttest. And I got the p-value from signed rank test for each pair. How do I use a Macro for ODS statement to output all the 57 P-values from Wilcoxon Signed Rank test? Thank you!

 

Below is my original code:


data kas2;
set kas;
diff_TC1= POSTTC1-PRETC1;
diff_TC2= POSTTC2-PRETC2;
diff_TC3= POSTTC3-PRETC3;
diff_TC4= POSTTC4-PRETC4;
diff_TC5= POSTTC5-PRETC5;
diff_TC6= POSTTC6-PRETC6;
diff_TC7= POSTTC7-PRETC7;

diff_EBC1= POSTEBC1-PREEBC1;
diff_EBC2= POSTEBC2-PREEBC2;
diff_EBC3= POSTEBC3-PREEBC3;
diff_EBC4= POSTEBC4-PREEBC4;
diff_EBC5= POSTEBC5-PREEBC5;
diff_EBC6= POSTEBC6-PREEBC6;
diff_EBC7= POSTEBC7-PREEBC7;
diff_EBC8= POSTEBC8-PREEBC8;
diff_EBC9= POSTEBC9-PREEBC9;
diff_EBC10= POSTEBC10-PREEBC10;
diff_EBC11= POSTEBC11-PREEBC11;

diff_TOP1= POSTTOP1-PRETOP1;
diff_TOP2= POSTTOP2-PRETOP2;
diff_TOP3= POSTTOP3-PRETOP3;
diff_TOP4= POSTTOP4-PRETOP4;
diff_TOP5= POSTTOP5-PRETOP5;
diff_TOP6= POSTTOP6-PRETOP6;
diff_TOP7= POSTTOP7-PRETOP7;
diff_TOP8= POSTTOP8-PRETOP8;
diff_TOP9= POSTTOP9-PRETOP9;
diff_TOP10= POSTTOP10-PRETOP10;
diff_TOP11= POSTTOP11-PRETOP11;
diff_TOP12= POSTTOP12-PRETOP12;
diff_TOP13= POSTTOP13-PRETOP13;
diff_TOP14= POSTTOP14-PRETOP14;
diff_TOP15= POSTTOP15-PRETOP15;
diff_TOP16= POSTTOP16-PRETOP16;
diff_TOP17= POSTTOP17-PRETOP17;
diff_TOP18= POSTTOP18-PRETOP18;
diff_TOP19= POSTTOP19-PRETOP19;
diff_TOP20= POSTTOP20-PRETOP20;
diff_TOP21= POSTTOP21-PRETOP21;

diff_MENT= POSTMENT-PREMENT;
diff_MENTRANK1 = POSTMENTRANK1-PREMENTRANK1;
diff_MENTRANK2 = POSTMENTRANK2-PREMENTRANK2;
diff_MENTRANK3 = POSTMENTRANK3-PREMENTRANK3;
diff_MENTRANK4 = POSTMENTRANK4-PREMENTRANK4;
diff_MENTRANK5 = POSTMENTRANK5-PREMENTRANK5;
diff_MENTRANK6 = POSTMENTRANK6-PREMENTRANK6;
diff_MENTRANK7 = POSTMENTRANK7-PREMENTRANK7;
diff_MENTRANK8 = POSTMENTRANK8-PREMENTRANK8;
diff_MENTRANK9 = POSTMENTRANK9-PREMENTRANK9;
diff_MENTRANK10 = POSTMENTRANK10-PREMENTRANK10;
diff_MENTRANK11 = POSTMENTRANK11-PREMENTRANK11;
diff_MENTRANK12 = POSTMENTRANK12-PREMENTRANK12;
diff_MENTRANK13 = POSTMENTRANK13-PREMENTRANK13;
diff_MENTRANK14 = POSTMENTRANK14-PREMENTRANK14;
diff_MENTRANK15 = POSTMENTRANK15-PREMENTRANK15;
diff_MENTRANK16 = POSTMENTRANK16-PREMENTRANK16;
diff_MENTRANK17 = POSTMENTRANK17-PREMENTRANK17;
diff_MENTRANK18 = POSTMENTRANK18-PREMENTRANK18;
run;

 

proc univariate data=kas2;
var diff_TC1--diff_MENTRANK17;
run;

 


Accepted Solutions
Solution
a week ago
SAS Super FREQ
Posts: 8,819

Re: How to use Macro to ODS P-values from Wilcoxon Signed Rank Test

[ Edited ]

Hi,
You could try putting
ODS TRACE ON/ LABEL;
before your PROC UNIVARIATE.

Unfortunately, no one can run your code because you send us your program that creates WORK.KAS2, but you do not send any data for the original dataset WORK.KAS.

However, using SASHELP.CLASS, you can capture the TestsForLocation output object , (which has pvalues) by using the ODS OUTPUT statement:

**1) run one time to see object name that holds pvalue;
ods trace on / label;
 proc univariate data=sashelp.class;
  var height weight;
run;
ods trace off;
  
**2) use object name (TestsForLocation) in ODS OUTPUT statement;
ods output TestsForLocation=univout;
proc univariate data=sashelp.class;
  var height weight;
run;
  
proc print data=univout;
title 'output dataset from univariate';
run;

Using PROC PRINT on the output dataset created by UNIVOUT, shows a table with VarName containing the value of the variable that was analyzed -- you can further refine what you see with PROC PRINT by selecting on other columns such as VarName and  Test or one of the other columns with a WHERE statement.

ods_output_univariate.png



cynthia

View solution in original post


All Replies
Solution
a week ago
SAS Super FREQ
Posts: 8,819

Re: How to use Macro to ODS P-values from Wilcoxon Signed Rank Test

[ Edited ]

Hi,
You could try putting
ODS TRACE ON/ LABEL;
before your PROC UNIVARIATE.

Unfortunately, no one can run your code because you send us your program that creates WORK.KAS2, but you do not send any data for the original dataset WORK.KAS.

However, using SASHELP.CLASS, you can capture the TestsForLocation output object , (which has pvalues) by using the ODS OUTPUT statement:

**1) run one time to see object name that holds pvalue;
ods trace on / label;
 proc univariate data=sashelp.class;
  var height weight;
run;
ods trace off;
  
**2) use object name (TestsForLocation) in ODS OUTPUT statement;
ods output TestsForLocation=univout;
proc univariate data=sashelp.class;
  var height weight;
run;
  
proc print data=univout;
title 'output dataset from univariate';
run;

Using PROC PRINT on the output dataset created by UNIVOUT, shows a table with VarName containing the value of the variable that was analyzed -- you can further refine what you see with PROC PRINT by selecting on other columns such as VarName and  Test or one of the other columns with a WHERE statement.

ods_output_univariate.png



cynthia

Contributor
Posts: 23

Macro for ODS P-values from Wilcoxon Signed Rank Test

I just ran the Wilconxon signed rank test for 57 pairs of pretest and posttest. And I got the p-value from signed rank test for each pair. How do I use a Macro for ODS statement to output all the 57 P-values from Wilcoxon Signed Rank test? Thank you!

 

Below is my original code:


data kas2;
set kas;
diff_TC1= POSTTC1-PRETC1;
diff_TC2= POSTTC2-PRETC2;
diff_TC3= POSTTC3-PRETC3;
diff_TC4= POSTTC4-PRETC4;
diff_TC5= POSTTC5-PRETC5;
diff_TC6= POSTTC6-PRETC6;
diff_TC7= POSTTC7-PRETC7;

diff_EBC1= POSTEBC1-PREEBC1;
diff_EBC2= POSTEBC2-PREEBC2;
diff_EBC3= POSTEBC3-PREEBC3;
diff_EBC4= POSTEBC4-PREEBC4;
diff_EBC5= POSTEBC5-PREEBC5;
diff_EBC6= POSTEBC6-PREEBC6;
diff_EBC7= POSTEBC7-PREEBC7;
diff_EBC8= POSTEBC8-PREEBC8;
diff_EBC9= POSTEBC9-PREEBC9;
diff_EBC10= POSTEBC10-PREEBC10;
diff_EBC11= POSTEBC11-PREEBC11;

diff_TOP1= POSTTOP1-PRETOP1;
diff_TOP2= POSTTOP2-PRETOP2;
diff_TOP3= POSTTOP3-PRETOP3;
diff_TOP4= POSTTOP4-PRETOP4;
diff_TOP5= POSTTOP5-PRETOP5;
diff_TOP6= POSTTOP6-PRETOP6;
diff_TOP7= POSTTOP7-PRETOP7;
diff_TOP8= POSTTOP8-PRETOP8;
diff_TOP9= POSTTOP9-PRETOP9;
diff_TOP10= POSTTOP10-PRETOP10;
diff_TOP11= POSTTOP11-PRETOP11;
diff_TOP12= POSTTOP12-PRETOP12;
diff_TOP13= POSTTOP13-PRETOP13;
diff_TOP14= POSTTOP14-PRETOP14;
diff_TOP15= POSTTOP15-PRETOP15;
diff_TOP16= POSTTOP16-PRETOP16;
diff_TOP17= POSTTOP17-PRETOP17;
diff_TOP18= POSTTOP18-PRETOP18;
diff_TOP19= POSTTOP19-PRETOP19;
diff_TOP20= POSTTOP20-PRETOP20;
diff_TOP21= POSTTOP21-PRETOP21;

diff_MENT= POSTMENT-PREMENT;
diff_MENTRANK1 = POSTMENTRANK1-PREMENTRANK1;
diff_MENTRANK2 = POSTMENTRANK2-PREMENTRANK2;
diff_MENTRANK3 = POSTMENTRANK3-PREMENTRANK3;
diff_MENTRANK4 = POSTMENTRANK4-PREMENTRANK4;
diff_MENTRANK5 = POSTMENTRANK5-PREMENTRANK5;
diff_MENTRANK6 = POSTMENTRANK6-PREMENTRANK6;
diff_MENTRANK7 = POSTMENTRANK7-PREMENTRANK7;
diff_MENTRANK8 = POSTMENTRANK8-PREMENTRANK8;
diff_MENTRANK9 = POSTMENTRANK9-PREMENTRANK9;
diff_MENTRANK10 = POSTMENTRANK10-PREMENTRANK10;
diff_MENTRANK11 = POSTMENTRANK11-PREMENTRANK11;
diff_MENTRANK12 = POSTMENTRANK12-PREMENTRANK12;
diff_MENTRANK13 = POSTMENTRANK13-PREMENTRANK13;
diff_MENTRANK14 = POSTMENTRANK14-PREMENTRANK14;
diff_MENTRANK15 = POSTMENTRANK15-PREMENTRANK15;
diff_MENTRANK16 = POSTMENTRANK16-PREMENTRANK16;
diff_MENTRANK17 = POSTMENTRANK17-PREMENTRANK17;
diff_MENTRANK18 = POSTMENTRANK18-PREMENTRANK18;
run;

 

proc univariate data=kas2;
var diff_TC1--diff_MENTRANK17;
run;

 

SAS Super FREQ
Posts: 197

Re: Macro for ODS P-values from Wilcoxon Signed Rank Test


Use ODS TRACE ON to identify the table of interest (or look at the documentation).

 

ods trace on;
proc univariate data=sashelp.class;
run;

 

Use that info from the log to create an ODS OUTPUT statement.

 

proc univariate data=sashelp.class;
   ods output testsforlocation=w;
run;

 

Then select just that parts that you want:

 

proc print; where test =: 'Signed'; run;

Super User
Posts: 11,121

Re: Macro for ODS P-values from Wilcoxon Signed Rank Test

Please refrain from making identical posts on this forum. It leads to multiple questions about your process/ data/ that may not get answered in multiple threads, people are duplicating effort and search engines that bring people to this site for help may not get the whole picture.

 

If a post belongs in a different area of the forum it will usually get moved if needed.

Super User
Posts: 7,422

Re: How to use Macro to ODS P-values from Wilcoxon Signed Rank Test

PLEASE DO NOT DOUBLE_POST!

@Reeza already told you that in https://communities.sas.com/t5/General-SAS-Programming/Macro-for-Wilcoxon-Signed-Rank-Test/m-p/40046...

 

I merged the threads.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 175 views
  • 0 likes
  • 5 in conversation