<?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 First.Variable Last.Variable to sum multiple observations in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708016#M26553</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to sum multiple observations with the&amp;nbsp;First.Variable Last.Variable feature, however it never works in adding all the observations together, it either gives me the first or last variable values&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data T_Total;&lt;BR /&gt;set T;&lt;BR /&gt;by m**;&amp;nbsp;&lt;BR /&gt;if first. m** then TOTAL_DAYS=0;&lt;BR /&gt;TOTAL_DAYS= sum (TOTAL_DAYS,SUPPLY_DAYS);&lt;BR /&gt;retain TOTAL_DAYS;&lt;BR /&gt;if last. m** then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I also tried changing the order of sentences, or using the&amp;nbsp;&lt;/P&gt;&lt;P&gt;TOTAL_DAYS= TOTAL_DAYS+SUPPLY_DAYS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Dec 2020 22:44:40 GMT</pubDate>
    <dc:creator>mariamabotaleb</dc:creator>
    <dc:date>2020-12-23T22:44:40Z</dc:date>
    <item>
      <title>First.Variable Last.Variable to sum multiple observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708016#M26553</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to sum multiple observations with the&amp;nbsp;First.Variable Last.Variable feature, however it never works in adding all the observations together, it either gives me the first or last variable values&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data T_Total;&lt;BR /&gt;set T;&lt;BR /&gt;by m**;&amp;nbsp;&lt;BR /&gt;if first. m** then TOTAL_DAYS=0;&lt;BR /&gt;TOTAL_DAYS= sum (TOTAL_DAYS,SUPPLY_DAYS);&lt;BR /&gt;retain TOTAL_DAYS;&lt;BR /&gt;if last. m** then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I also tried changing the order of sentences, or using the&amp;nbsp;&lt;/P&gt;&lt;P&gt;TOTAL_DAYS= TOTAL_DAYS+SUPPLY_DAYS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 22:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708016#M26553</guid>
      <dc:creator>mariamabotaleb</dc:creator>
      <dc:date>2020-12-23T22:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: First.Variable Last.Variable to sum multiple observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708021#M26554</link>
      <description>&lt;P&gt;There's no double-asterisk in this syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And instead of &lt;FONT face="courier new,courier"&gt;TOTAL_DAYS=sum (TOTAL_DAYS,SUPPLY_DAYS);&lt;/FONT&gt; you probably want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;total_days+supply_days;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Better yet, don't program this yourself in a DATA step. Use PROC SUMMARY, where this is a built-in feature. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 00:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708021#M26554</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-24T00:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: First.Variable Last.Variable to sum multiple observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708029#M26555</link>
      <description>&lt;P&gt;When you use first. and last. variables, there should not be a space after the dot.&amp;nbsp; Incorrect:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first. m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Correct:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first.m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And as was noted, asterisks are not a legitimate part of a variable name.&amp;nbsp; Clean up the obvious inaccuracies, and see if any problems remain.&amp;nbsp; Your syntax for summing should work, even if other choices exist.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 02:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708029#M26555</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-12-24T02:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: First.Variable Last.Variable to sum multiple observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708041#M26556</link>
      <description>&lt;P&gt;Make sure that TOTAL_DAYS does not already exist as a variable in the input dataset T.&amp;nbsp; Because if it does then as you read observations from T the value you calculated after reading the pervious observation will be overwritten with what is read from T.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 05:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-Variable-Last-Variable-to-sum-multiple-observations/m-p/708041#M26556</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-24T05:03:05Z</dc:date>
    </item>
  </channel>
</rss>

