<?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 How could I get RMSE and MAE for each repeat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447000#M112222</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate RMSE and MAE. With data data4rmse I could get one&amp;nbsp;&lt;SPAN&gt;RMSE and MAE using following code. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now I have data EQ with repeating the experiment for 3 times. How could I get RMSE and MAE for each repeat and output them into one table?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data4rmse;
input ID bmi dm bmi_me;
cards;
1 13 40 8
2 13 29 37
3 30 14 25
4 38 38 23
;
run;
	data rmse;
    retain square_error_sum abs_error_sum; 
    set data4rmse 
        end=last /* Flag for the last observation */
        ;
    error = BMI - BMI_me; /* Calculate simple error */
    square_error = error * error; /* error^2 */
    if _n_ eq 1 then do;
        /* Initialize the sums */
        square_error_sum = square_error; 
        abs_error_sum = abs(error); 
        end;
    else do;
        /* Add to the sum */
        square_error_sum = square_error_sum + square_error; 
        abs_error_sum = abs_error_sum + abs(error);
    end;
    if last then do;
        /* Calculate RMSE and MAE and store in SAS data set. */
        mae = abs_error_sum/_n_;
        rmse = sqrt(square_error_sum/_n_); 
        end;
run;

data eq;
input repeat ID bmi dm bmi_me;
cards;
1 1 13 40 8
1 2 13 29 37
1 3 30 14 25
1 4 38 38 23
2 1 30 45 19
2 2 30 20 14
2 3 67 13 14
2 4 13 27 13
3 1 33 23 46
3 2 13 12 56
3 3 13 13 34
3 4 13 45 13
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Mar 2018 05:02:29 GMT</pubDate>
    <dc:creator>xiangpang</dc:creator>
    <dc:date>2018-03-20T05:02:29Z</dc:date>
    <item>
      <title>How could I get RMSE and MAE for each repeat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447000#M112222</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate RMSE and MAE. With data data4rmse I could get one&amp;nbsp;&lt;SPAN&gt;RMSE and MAE using following code. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now I have data EQ with repeating the experiment for 3 times. How could I get RMSE and MAE for each repeat and output them into one table?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data4rmse;
input ID bmi dm bmi_me;
cards;
1 13 40 8
2 13 29 37
3 30 14 25
4 38 38 23
;
run;
	data rmse;
    retain square_error_sum abs_error_sum; 
    set data4rmse 
        end=last /* Flag for the last observation */
        ;
    error = BMI - BMI_me; /* Calculate simple error */
    square_error = error * error; /* error^2 */
    if _n_ eq 1 then do;
        /* Initialize the sums */
        square_error_sum = square_error; 
        abs_error_sum = abs(error); 
        end;
    else do;
        /* Add to the sum */
        square_error_sum = square_error_sum + square_error; 
        abs_error_sum = abs_error_sum + abs(error);
    end;
    if last then do;
        /* Calculate RMSE and MAE and store in SAS data set. */
        mae = abs_error_sum/_n_;
        rmse = sqrt(square_error_sum/_n_); 
        end;
run;

data eq;
input repeat ID bmi dm bmi_me;
cards;
1 1 13 40 8
1 2 13 29 37
1 3 30 14 25
1 4 38 38 23
2 1 30 45 19
2 2 30 20 14
2 3 67 13 14
2 4 13 27 13
3 1 33 23 46
3 2 13 12 56
3 3 13 13 34
3 4 13 45 13
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 05:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447000#M112222</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-03-20T05:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: How could I get RMSE and MAE for each repeat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447036#M112229</link>
      <description>&lt;P&gt;Something like this, perhaps?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rmse;
  square_error_sum = 0; 
  abs_error_sum = 0; 
  do n=1 by 1 until(last.repeat);
    set eq;
    by repeat;
    error = BMI - BMI_me; /* Calculate simple error */
    square_error = error * error; /* error^2 */
    square_error_sum + square_error; 
    abs_error_sum + abs(error); 
    end;
  /* Calculate RMSE and MAE and store in SAS data set. */
  mae = abs_error_sum/n;
  rmse = sqrt(square_error_sum/n);
  keep repeat mae rmse n;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I assumed that you only really wanted one row for each repeat. I included the count (n), in case you have a different number of observations in each repeat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The statement "a+b;" is called a SUM statement, it is equivalent to "retain a 0; a=sum(a,b);", which can save you a lot of coding.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 09:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447036#M112229</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-20T09:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: How could I get RMSE and MAE for each repeat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447074#M112242</link>
      <description>&lt;P&gt;Thanks for your teaching and code. I am happy to learn it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 12:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-could-I-get-RMSE-and-MAE-for-each-repeat/m-p/447074#M112242</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-03-20T12:51:50Z</dc:date>
    </item>
  </channel>
</rss>

