<?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: sum up the number for a specific id in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729122#M28320</link>
    <description>&lt;P&gt;If your goal is to add the total number of fish caught on a trip to the detailed data of the trip you can use PROC SQL and only group on trip. In that way the summary statistics are merged to the original data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data catch;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input trip $ person $ fish;&lt;BR /&gt;datalines;&lt;BR /&gt;A John 2&lt;BR /&gt;A Dave 4&lt;BR /&gt;A Kim 3&lt;BR /&gt;B Brian 1&lt;BR /&gt;B Alison 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table catch_stats as&lt;BR /&gt;select trip, person, fish, sum(fish) as total_catch&lt;BR /&gt;from catch&lt;BR /&gt;group by trip&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;will produce a dataset with the total number of fish per trip added:&lt;/P&gt;&lt;P&gt;trip person fish total_catch&lt;BR /&gt;A Kim 3 9&lt;BR /&gt;A John 2 9&lt;BR /&gt;A Dave 4 9&lt;BR /&gt;B Alison 2 3&lt;BR /&gt;B Brian 1 3&lt;/P&gt;</description>
    <pubDate>Thu, 25 Mar 2021 16:23:58 GMT</pubDate>
    <dc:creator>DaanDNR</dc:creator>
    <dc:date>2021-03-25T16:23:58Z</dc:date>
    <item>
      <title>sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729101#M28312</link>
      <description>&lt;P&gt;I have my data in the following format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Person&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Fish&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; John&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dave&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Kim&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Brian&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Alison&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't care about the Person.&amp;nbsp; I care about the number of fish per trip.&amp;nbsp; So I am trying to sum up all the total fish for each trip.&amp;nbsp; So I am trying to get this converted into the following output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fish&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be greatly appreciated. Thanks.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 15:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729101#M28312</guid>
      <dc:creator>elopomorph88</dc:creator>
      <dc:date>2021-03-25T15:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729102#M28313</link>
      <description>PROC MEANS?&lt;BR /&gt;&lt;BR /&gt;proc means data=have N SUM MEAN;&lt;BR /&gt;class trip;&lt;BR /&gt;var fish;&lt;BR /&gt;ods output summary=want;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Output data is saved in the WANT data set as well as displayed. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2021 15:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729102#M28313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-25T15:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729112#M28315</link>
      <description>That is helpful but I forgot another part of it. I am trying to create a new dataset that has the sum of the total fish for each trip and also the new dataset includes other data variables from the dataset. Here is my example with more detail:&lt;BR /&gt;&lt;BR /&gt;Trip Person Fish Date State&lt;BR /&gt;A John 2 May 1 NC&lt;BR /&gt;A Dave 4 May 1 NC&lt;BR /&gt;A Kim 3 May 1 NC&lt;BR /&gt;B Brian 1 May 10 GA&lt;BR /&gt;B Alison 2 May 10 GA&lt;BR /&gt;&lt;BR /&gt;So I want to also have the Date and State data included in the new dataset.</description>
      <pubDate>Thu, 25 Mar 2021 15:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729112#M28315</guid>
      <dc:creator>elopomorph88</dc:creator>
      <dc:date>2021-03-25T15:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729115#M28316</link>
      <description>I answered the question you asked for the output shown.... You don't actually show what you want that final result to look like similar to your first post.</description>
      <pubDate>Thu, 25 Mar 2021 16:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729115#M28316</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-25T16:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729118#M28318</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269053"&gt;@elopomorph88&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;That is helpful but I forgot another part of it. &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you please take some time and give us a complete and clear description of the problem and the desired output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;I am trying to create a new dataset that has the sum of the total fish for each trip and also the new dataset includes other data variables from the dataset. Here is my example with more detail:&lt;BR /&gt;&lt;BR /&gt;Trip Person Fish Date State&lt;BR /&gt;A John 2 May 1 NC&lt;BR /&gt;A Dave 4 May 1 NC&lt;BR /&gt;A Kim 3 May 1 NC&lt;BR /&gt;B Brian 1 May 10 GA&lt;BR /&gt;B Alison 2 May 10 GA&lt;BR /&gt;&lt;BR /&gt;So I want to also have the Date and State data included in the new dataset.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are date and state always the same for each Trip? Or can they vary within trip? These are the types of things we need to know, so we don't provide an answer, and then you come back again and say you left another thing out.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729118#M28318</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-25T16:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729120#M28319</link>
      <description>Yes, Date and State are always the same for each trip.&lt;BR /&gt;&lt;BR /&gt;So the problem is that I have multiple rows for the same trip because there were multiple people on the same trip. Here is another example of my data. Hopefully it won't be clear.&lt;BR /&gt;&lt;BR /&gt;Trip Person Fish Date State&lt;BR /&gt;A John 2 May 1 NC&lt;BR /&gt;A Dave 4 May 1 NC&lt;BR /&gt;A Kim 3 May 1 NC&lt;BR /&gt;B Brian 1 May 10 GA&lt;BR /&gt;B Alison 2 May 10 GA&lt;BR /&gt;&lt;BR /&gt;So I am trying to generate a new dataset that sums up the fish for each trip and carries over the details from the other variables. So the new dataset will look like this:&lt;BR /&gt;&lt;BR /&gt;Trip Fish Date State&lt;BR /&gt;A 9 May 1 NC&lt;BR /&gt;B 3 May 10 GA&lt;BR /&gt;&lt;BR /&gt;Thanks for the help!</description>
      <pubDate>Thu, 25 Mar 2021 16:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729120#M28319</guid>
      <dc:creator>elopomorph88</dc:creator>
      <dc:date>2021-03-25T16:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729122#M28320</link>
      <description>&lt;P&gt;If your goal is to add the total number of fish caught on a trip to the detailed data of the trip you can use PROC SQL and only group on trip. In that way the summary statistics are merged to the original data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data catch;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input trip $ person $ fish;&lt;BR /&gt;datalines;&lt;BR /&gt;A John 2&lt;BR /&gt;A Dave 4&lt;BR /&gt;A Kim 3&lt;BR /&gt;B Brian 1&lt;BR /&gt;B Alison 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table catch_stats as&lt;BR /&gt;select trip, person, fish, sum(fish) as total_catch&lt;BR /&gt;from catch&lt;BR /&gt;group by trip&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;will produce a dataset with the total number of fish per trip added:&lt;/P&gt;&lt;P&gt;trip person fish total_catch&lt;BR /&gt;A Kim 3 9&lt;BR /&gt;A John 2 9&lt;BR /&gt;A Dave 4 9&lt;BR /&gt;B Alison 2 3&lt;BR /&gt;B Brian 1 3&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729122#M28320</guid>
      <dc:creator>DaanDNR</dc:creator>
      <dc:date>2021-03-25T16:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729129#M28322</link>
      <description>&lt;P&gt;use the PROC MEANS code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;above, with the ID statement added&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id date state;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729129#M28322</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-25T16:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729134#M28325</link>
      <description>If date and state are the same across the rows and you expect them to be, either just add them to your CLASS/BY statement or include them in an ID statement. If they are not the same then you need to decide how to handle those differences explicitly. &lt;BR /&gt;&lt;BR /&gt;proc means data=have N SUM MEAN NWAY;&lt;BR /&gt;class trip date state;&lt;BR /&gt;var fish;&lt;BR /&gt;ods output summary=want;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729134#M28325</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-25T16:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729138#M28329</link>
      <description>you might want to add a types statement to only select the desired types eg types trip*date*state;&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729138#M28329</guid>
      <dc:creator>DaanDNR</dc:creator>
      <dc:date>2021-03-25T16:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: sum up the number for a specific id</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729141#M28330</link>
      <description>The NWAY option on the PROC MEANS statement should ensure that only the highest level is reported in the output dataset, but the TYPES statement is another way to do that.</description>
      <pubDate>Thu, 25 Mar 2021 17:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sum-up-the-number-for-a-specific-id/m-p/729141#M28330</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-25T17:06:32Z</dc:date>
    </item>
  </channel>
</rss>

