<?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: Making a new accumulating column by another grouped variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849804#M37180</link>
    <description>&lt;P&gt;Needless to say, this code is untested since I do not have workable data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can use this as a template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data = Final.opioiddeaths nway;
   where year = 2020;
   class state;
   var DataValue;
   output out = want sum =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Dec 2022 08:24:37 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-12-15T08:24:37Z</dc:date>
    <item>
      <title>Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849787#M37173</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still quite new to SAS, so I'm looking for help. I'm trying to create a new variable that accumulates a numeric variable, Data Value, and is specific to the year 2020 for each state. My current data has multiple entries for each state for 2020 because there are observations for each month. I'm not interested in the months, just the year totals per state. My current code is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data FinalOutput;
set Final.opioiddeaths;
where Indicator='Number of Drug Overdose Deaths';
keep State Indicator Year 'Data Value'n TotalDeaths;
by State;
if Year='2020' then output;
retain TotalDeaths 0;
TotalDeaths=TotalDeaths+'Data Value'n;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output shows only the observations for 2020. However, my new variable TotalDeaths is an accumulation of Data Values from all years. Is there a way in the data step for only the TotalDeaths in 2020 to accumulate by State? If this changes anything, I considered grouping it by Year but I need to do it by State as I am using it to merge tables later on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 06:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849787#M37173</guid>
      <dc:creator>cpcb123</dc:creator>
      <dc:date>2022-12-15T06:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849789#M37174</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437725"&gt;@cpcb123&lt;/a&gt;&amp;nbsp;, can you show us som esample of your data? Makes it much easier to provide a usable code answer.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 06:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849789#M37174</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-15T06:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849793#M37175</link>
      <description>&lt;P&gt;This is my current output. Is there anything else I can send to help as well?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (9).png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78559i73728E1A0FF81208/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (9).png" alt="Screenshot (9).png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 07:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849793#M37175</guid>
      <dc:creator>cpcb123</dc:creator>
      <dc:date>2022-12-15T07:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849794#M37176</link>
      <description>&lt;P&gt;So you want all observations from your original data set, but you want to accumulate the variable TotalDeaths when year = 2020. Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, please be very specific about what your data looks like (preferably posted as a data step) and your desired result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 07:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849794#M37176</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-15T07:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849797#M37177</link>
      <description>Yes, that is correct. However, would it be easier to assign TotalDeaths as a sum of Data Value for each state in 2020? I'm sorry I know that is not my original question</description>
      <pubDate>Thu, 15 Dec 2022 07:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849797#M37177</guid>
      <dc:creator>cpcb123</dc:creator>
      <dc:date>2022-12-15T07:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849799#M37178</link>
      <description>&lt;P&gt;It depends on what you want to do? If your desired result is a simple sum grouped by State for the year 2020, then there is no need for an accumulated variable in a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 08:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849799#M37178</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-15T08:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849800#M37179</link>
      <description>Yes true. How would I create that sum then?</description>
      <pubDate>Thu, 15 Dec 2022 08:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849800#M37179</guid>
      <dc:creator>cpcb123</dc:creator>
      <dc:date>2022-12-15T08:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Making a new accumulating column by another grouped variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849804#M37180</link>
      <description>&lt;P&gt;Needless to say, this code is untested since I do not have workable data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can use this as a template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data = Final.opioiddeaths nway;
   where year = 2020;
   class state;
   var DataValue;
   output out = want sum =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 08:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Making-a-new-accumulating-column-by-another-grouped-variable/m-p/849804#M37180</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-15T08:24:37Z</dc:date>
    </item>
  </channel>
</rss>

