<?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: iterative computation by groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142309#M28524</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Xia and Tom for your time and codes.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5em; font-size: 10pt;"&gt;Your answers have been very helpful, &lt;/SPAN&gt;especially&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="line-height: 19.5px;"&gt;because I had a chance to compare both code (proc sql and data step) and understand the logic. &lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5em;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 Jun 2014 20:05:52 GMT</pubDate>
    <dc:creator>MetinBulus</dc:creator>
    <dc:date>2014-06-14T20:05:52Z</dc:date>
    <item>
      <title>iterative computation by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142306#M28521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;I have difficulty writing a code in proc sql to do the following iterative computation. &lt;/P&gt;&lt;P&gt;The data with three groups looks like this (first ten observations),&lt;/P&gt;&lt;P&gt;Group Var&lt;/P&gt;&lt;H3&gt;&lt;SPAN style="color: #575757;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;STRONG&gt;60&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG style="color: #575757;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20&lt;/STRONG&gt;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG style="color: #575757;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .23&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .37&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .10&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .10&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .57&lt;/STRONG&gt;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .43&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;and within each group numbers add up to one. &lt;/P&gt;&lt;P&gt;I would like to get the sum the squared difference of all numbers.&lt;/P&gt;&lt;P&gt;For example for the first group in bold, I would like to do something like this:SUM[ (.60-.20)**2 + (.60-.20)**2 + (.20-.20)**2], &lt;/P&gt;&lt;P&gt;for the second there will be like sum of ten squared differences. Finally I would like divide this number by the number of observations in each group. &lt;/P&gt;&lt;P&gt;How can I do this with proc sql&lt;/P&gt;&lt;P&gt;Thank you for your help,&lt;/P&gt;&lt;P&gt;Metin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 06:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142306#M28521</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2014-06-14T06:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterative computation by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142307#M28522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am afraid it is hard for SQL but easy for data step. Are you trying to get somewhat model's average square error ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input Group Var&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .60
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .23
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .37
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .10
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .20
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .10
3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .57
3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .43
;
run;
data want;
 set have;
 by group;
 array x{100} _temporary_;
 if first.group then do;n=0; sum=0;call missing(of x{*}) ;end;
 n+1;
 x{n}=var;
 if last.group then do;
&amp;nbsp; do i=1 to n-1;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do j=i+1 to n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum+(x{i}-x{j})**2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;
&amp;nbsp; end;
&amp;nbsp; chisq=divide(sum,n); output;
 end;
drop i j n var;
 run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 13:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142307#M28522</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-06-14T13:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: iterative computation by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142308#M28523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just take all possible combinations (FULL JOIN) of the data with itself.&amp;nbsp; This will give you the values you listed, but also the same with the numbers in the opposite order.&amp;nbsp; It will also include where you have crossed value with itself, but that will contribute 0 to the total sum of squares.&amp;nbsp; So just divide the sum by 2 to get back to the number you requested.&lt;/P&gt;&lt;P&gt;To find the number in each group notice that if N is 3 then there are 3*3 rows when crossed with itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; want &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; a.grp&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , sum( (a.val - b.val) ** &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; )/&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sumsq &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , (calculated sumsq)/sqrt(count(*)) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; meansq&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have a&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , have b&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; a.grp = b.grp&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;order&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 13:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142308#M28523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-14T13:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: iterative computation by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142309#M28524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Xia and Tom for your time and codes.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5em; font-size: 10pt;"&gt;Your answers have been very helpful, &lt;/SPAN&gt;especially&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="line-height: 19.5px;"&gt;because I had a chance to compare both code (proc sql and data step) and understand the logic. &lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5em;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 20:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterative-computation-by-groups/m-p/142309#M28524</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2014-06-14T20:05:52Z</dc:date>
    </item>
  </channel>
</rss>

