<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculation of S using proc univariate (Wilcoxon Signed Rank Test) for small n in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculation-of-S-using-proc-univariate-Wilcoxon-Signed-Rank-Test/m-p/757972#M239292</link>
    <description>&lt;P&gt;If you want to reference a document then write code it is a good idea to use variable names that at least come close to the ones the document uses so we can follow what you may be attempting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing you may want to consider is this is incorrect:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/*Run SAS' Wilcoxon signed rank test*/
proc univariate data = test;
	var v1 v2;
run; 
/*note that here S = 7.5*/&lt;/LI-CODE&gt;
&lt;P&gt;Reread your output. S=7.5 for V2. For V1 S=39.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run a test on the Signed Rank of difference between V1 and V2 you would use Proc univariate on your set TEST2 and use that for your comparison for the result, not for the single variables. If you run&lt;/P&gt;
&lt;PRE&gt;proc univariate data = test2;
	var diffvar;
run; &lt;/PRE&gt;
&lt;P&gt;The Signed rank test result is 29.5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Convoluted code but matched when compared to the correct value.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 01:11:58 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-29T01:11:58Z</dc:date>
    <item>
      <title>Calculation of S using proc univariate (Wilcoxon Signed Rank Test) for small n</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-of-S-using-proc-univariate-Wilcoxon-Signed-Rank-Test/m-p/757971#M239291</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested in writing code that calculates S from the Wilcoxon Signed Rank test (see documentation &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_details17.htm" target="_self"&gt;here&lt;/A&gt;). I have been written code that correctly calculates S when n &amp;gt; 20, however, I have not been successful when n is less than 20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the bottom of this post is an example. You will notice that the proc univariate procedure returns S = 7.5, but when I write code that attempts to perform what the Wilcoxon Signed Rank test documentation says it is doing, I get a different value for S.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight on what I am doing wrong, or how I should calculate S for small n?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*made up data (the data is scorelines from Celtic Football Club in Scotland, but that doesn't matter)*/
data test;
input v1
	  v2;
datalines;
5 1
1 1
6 0
1 0
1 2
3 0 
5 0 
2 1
3 2
1 0
3 0
1 0 
;

/*Run SAS' Wilcoxon signed rank test*/
proc univariate data = test;
	var v1 v2;
run; 
/*note that here S = 7.5*/

/*derive x_[i} (called diffVar) */
data test2;
	set test;
	diffVar = v1 - v2;
	diffVarAbs = abs(diffVar);  
run; 

/* discard observations that have x_{i} = \mu_{0} */
data test3; 
	set test2;
	WHERE diffVar ne 0 ; 
run; 

/*derive r_{i}*/
proc rank data = test3 out = test4;
	var diffVarAbs;
	ranks Finish;
run; 

/* filtering observations such that x_{i} &amp;gt; \mu_{0}*/
data test5;
	set test4; 
	WHERE diffVar &amp;gt; 0;
run; 

proc sql noprint; 
	select count(v1) into: constant2 TRIMMED
	from test3;
run; 

*constant3 is the sum of r_{i}s*/;
proc sql noprint;
	select sum(Finish) into: constant3 TRIMMED
	from test5;
quit; 

/*calculate S*/
proc sql; 
	select &amp;amp;constant3 - (&amp;amp;constant2 * (&amp;amp;constant2 + 1)) / 4 into: constant4 TRIMMED
	FROM test5  ;
quit; 
/*note that now S = 29.5*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 00:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-of-S-using-proc-univariate-Wilcoxon-Signed-Rank-Test/m-p/757971#M239291</guid>
      <dc:creator>pywils</dc:creator>
      <dc:date>2021-07-29T00:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation of S using proc univariate (Wilcoxon Signed Rank Test) for small n</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-of-S-using-proc-univariate-Wilcoxon-Signed-Rank-Test/m-p/757972#M239292</link>
      <description>&lt;P&gt;If you want to reference a document then write code it is a good idea to use variable names that at least come close to the ones the document uses so we can follow what you may be attempting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing you may want to consider is this is incorrect:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/*Run SAS' Wilcoxon signed rank test*/
proc univariate data = test;
	var v1 v2;
run; 
/*note that here S = 7.5*/&lt;/LI-CODE&gt;
&lt;P&gt;Reread your output. S=7.5 for V2. For V1 S=39.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run a test on the Signed Rank of difference between V1 and V2 you would use Proc univariate on your set TEST2 and use that for your comparison for the result, not for the single variables. If you run&lt;/P&gt;
&lt;PRE&gt;proc univariate data = test2;
	var diffvar;
run; &lt;/PRE&gt;
&lt;P&gt;The Signed rank test result is 29.5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Convoluted code but matched when compared to the correct value.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 01:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-of-S-using-proc-univariate-Wilcoxon-Signed-Rank-Test/m-p/757972#M239292</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-29T01:11:58Z</dc:date>
    </item>
  </channel>
</rss>

