<?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 total and average values across observations using the data step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61576#M17483</link>
    <description>We have a simple SAS program in which we want to loop through the observations twice.  &lt;BR /&gt;
The first time we will add up a column across all the rows and get the total and average value.&lt;BR /&gt;
For the second loop we will compare the value from the specific row against the total and/or average mentioned above and make a decision to take certain actions for the specific row.&lt;BR /&gt;
So the questions may be:&lt;BR /&gt;
1.	How do we loop through more than once (using the SET statement) in a data step?   Or &lt;BR /&gt;
2.	Can we pass a value (the total/average) from one data step to another data step?   That is, one loop through per data step using the SET statement.  Or&lt;BR /&gt;
3.	Is there an easy way to obtain the total/average value across all of the observations? &lt;BR /&gt;
&lt;BR /&gt;
Thank you so much if someone can shed light on this question.&lt;BR /&gt;
&lt;BR /&gt;
   JC</description>
    <pubDate>Tue, 11 Jan 2011 19:54:20 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-01-11T19:54:20Z</dc:date>
    <item>
      <title>total and average values across observations using the data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61576#M17483</link>
      <description>We have a simple SAS program in which we want to loop through the observations twice.  &lt;BR /&gt;
The first time we will add up a column across all the rows and get the total and average value.&lt;BR /&gt;
For the second loop we will compare the value from the specific row against the total and/or average mentioned above and make a decision to take certain actions for the specific row.&lt;BR /&gt;
So the questions may be:&lt;BR /&gt;
1.	How do we loop through more than once (using the SET statement) in a data step?   Or &lt;BR /&gt;
2.	Can we pass a value (the total/average) from one data step to another data step?   That is, one loop through per data step using the SET statement.  Or&lt;BR /&gt;
3.	Is there an easy way to obtain the total/average value across all of the observations? &lt;BR /&gt;
&lt;BR /&gt;
Thank you so much if someone can shed light on this question.&lt;BR /&gt;
&lt;BR /&gt;
   JC</description>
      <pubDate>Tue, 11 Jan 2011 19:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61576#M17483</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-11T19:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: total and average values across observations using the data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61577#M17484</link>
      <description>&amp;gt; 1.	How do we loop through more than once (using the SET statement) in a data step?&lt;BR /&gt;&lt;BR /&gt;
By reading the input dataset more than once using set statement(s).&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; 2.	Can we pass a value (the total/average) from one data step to another data step?&lt;BR /&gt;&lt;BR /&gt;
Yes, we can.&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; 3.	Is there an easy way to obtain the total/average value across all of the observations?&lt;BR /&gt; &lt;BR /&gt;
Yes, there is.&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
But this is much easier with proc sql, since unlike other sql implementations, it automatically merges back the summary stats. Below assuming no missing values:&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;proc&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;sql&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;name,&amp;nbsp;age,&amp;nbsp;mean(age)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;meanAge&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;,&amp;nbsp;ifc(age&amp;lt;(calculated&amp;nbsp;meanAge),&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#800080;font-family:Courier New;font-size:10pt;"&gt;"below"&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#800080;font-family:Courier New;font-size:10pt;"&gt;"at&amp;nbsp;or&amp;nbsp;above"&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;label&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;name&amp;nbsp;like&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#800080;font-family:Courier New;font-size:10pt;"&gt;"A%"&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;quit&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;on&amp;nbsp;lst&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Age&amp;nbsp;&amp;nbsp;&amp;nbsp;meanAge&amp;nbsp;&amp;nbsp;label&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;-----------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Alfred&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13.5&amp;nbsp;&amp;nbsp;at&amp;nbsp;or&amp;nbsp;above&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Alice&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13.5&amp;nbsp;&amp;nbsp;below&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2011 20:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61577#M17484</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-01-11T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: total and average values across observations using the data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61578#M17485</link>
      <description>Chang, thank you for the information.  Will update or close this record soon.&lt;BR /&gt;
&lt;BR /&gt;
Regards,</description>
      <pubDate>Wed, 12 Jan 2011 15:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/total-and-average-values-across-observations-using-the-data-step/m-p/61578#M17485</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-12T15:15:44Z</dc:date>
    </item>
  </channel>
</rss>

