<?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 to calculate the average of a variable per subject with multiple observations and missing data? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784234#M250235</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new variable that is the average of a variable V1 for every subject. Each subject has 3 rows containing values for V1 that were taken at 3 different time points. I can't calculate the average using a data step: average=(total_V1 / 3) because some subjects have 1-3 missing values for V1. Therefore, for those subjects that are missing V1 values it should be divided by 1 or 2 for example not 3. I can't figure out how to create a variable to go in the denominator of my average calculation to make the numbers accurate, please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of how the data exists:&lt;/P&gt;&lt;P&gt;id.&amp;nbsp; &amp;nbsp; V1&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 03:40:29 GMT</pubDate>
    <dc:creator>meghanrm</dc:creator>
    <dc:date>2021-12-06T03:40:29Z</dc:date>
    <item>
      <title>How to calculate the average of a variable per subject with multiple observations and missing data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784234#M250235</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new variable that is the average of a variable V1 for every subject. Each subject has 3 rows containing values for V1 that were taken at 3 different time points. I can't calculate the average using a data step: average=(total_V1 / 3) because some subjects have 1-3 missing values for V1. Therefore, for those subjects that are missing V1 values it should be divided by 1 or 2 for example not 3. I can't figure out how to create a variable to go in the denominator of my average calculation to make the numbers accurate, please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of how the data exists:&lt;/P&gt;&lt;P&gt;id.&amp;nbsp; &amp;nbsp; V1&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 03:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784234#M250235</guid>
      <dc:creator>meghanrm</dc:creator>
      <dc:date>2021-12-06T03:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the average of a variable per subject with multiple observations and missing da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784238#M250238</link>
      <description>&lt;P&gt;You should always show what you expect an output data set to look like. Do you need a data set for further manipulation or a report for people read?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to get a data set:&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class id;
   var v1;
   output out=summary (drop=_:) mean=;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 07:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784238#M250238</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-06T07:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the average of a variable per subject with multiple observations and missing da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784246#M250240</link>
      <description>Sorry I am new to posting on here. I need a data set for further manipulation. I am trying to create a new average variable and I have already written the code to get the total for the numerator of the average calculation but I can't figure out what code would work for the denominator being that subjects with missing data should not be divided by 3</description>
      <pubDate>Mon, 06 Dec 2021 07:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784246#M250240</guid>
      <dc:creator>meghanrm</dc:creator>
      <dc:date>2021-12-06T07:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the average of a variable per subject with multiple observations and missing da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784280#M250250</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386369"&gt;@meghanrm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry I am new to posting on here. I need a data set for further manipulation. I am trying to create a new average variable and I have already written the code to get the total for the numerator of the average calculation but I can't figure out what code would work for the denominator being that subjects with missing data should not be divided by 3&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use PROC SUMMARY, as explained by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; and then do the "further manipulation" in the output from PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which brings up the question: what "further manipulation" do you want to do? Perhaps this is already available in SAS (for example, PROC STDIZE) and so maybe PROC SUMMARY isn't needed.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 11:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-average-of-a-variable-per-subject-with/m-p/784280#M250250</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-06T11:45:39Z</dc:date>
    </item>
  </channel>
</rss>

