<?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: Summarizing and Adding a total column in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631923#M187270</link>
    <description>&lt;P&gt;Most of us will not download Microsoft Office files, as they are security risks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide your example data in the text of your message, as DATA step code. You can show us a screen capture of the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Mar 2020 15:36:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-03-13T15:36:35Z</dc:date>
    <item>
      <title>Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631920#M187268</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;everyone&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached some dummy data&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a total column into the dataset which is a count of the total visits per patient for all service types combined&lt;/P&gt;&lt;P&gt;And I would also like ti create a summary as displayed in the output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631920#M187268</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-13T15:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631923#M187270</link>
      <description>&lt;P&gt;Most of us will not download Microsoft Office files, as they are security risks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide your example data in the text of your message, as DATA step code. You can show us a screen capture of the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631923#M187270</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-13T15:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631926#M187273</link>
      <description>&lt;P&gt;What are the rules for calculating admissions and patients?&lt;BR /&gt;Please ensure this accurately represents your actual data so it will work as designed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, if you can provide data as a data step it helps others generate working solutions faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are instructions on how to provide sample data as a data step:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;
&lt;P&gt;everyone&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached some dummy data&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a total column into the dataset which is a count of the total visits per patient for all service types combined&lt;/P&gt;
&lt;P&gt;And I would also like ti create a summary as displayed in the output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631926#M187273</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-13T15:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631927#M187274</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sasdata; 
  input Patient $ Admission $ Service_Date Service;
cards;
ABC   ABCD   77   5
ABC   ABCD   84   5
ABC   ABCD  100   5
ABC   ABCD  105   5
ABC   ABCD  170   6
ABC   ABCD  201   6
ABC   ABCD   82   6
ABC   ABCD  181   7
ABC   ABCD  126   7
ABC   ABCD  230   7
DEF   DEFA  77    7
DEF   DEFA  84    8
DEF   DEFA  100   13
DEF   DEFA  105   6
DEF   DEFA  170   8
DEF   DEFA  201  13
DEF   DEFA  82    5
DEF   DEFA  181   5
DEF   DEFA  126   5
DEF   DEFA  230   5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to add a column to the above dataset that also calculates the total visits per patient&amp;nbsp;&lt;/P&gt;&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;10&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631927#M187274</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-13T15:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631930#M187277</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to add a column to the above dataset that also calculates the total visits per patient&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Each record in the data set is considered a visit?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631930#M187277</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-13T15:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631931#M187278</link>
      <description>Yes&lt;BR /&gt;every unique combination of service date and admission is considered a visit</description>
      <pubDate>Fri, 13 Mar 2020 15:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631931#M187278</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-13T15:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631938#M187282</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as

/*By Service level calculations*/
select put(service, z8.) as Service, count(*) as total_visits, count(distinct patient) as Patients, count(distinct admission) as Admissions
from have
group by service

union

/*Total calculations*/
select "Total" as Service, count(*) as Total_Visits, count(distinct Patient) as Patients, count(distinct admission) as Admissions
from have;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note I converted Service to a character variable, if it's already a character variable you can drop that but if you want a total line that's how you do it. You cannot do a total using PROC MEANS because it won't work correctly for distinct counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sasdata; 
  input Patient $ Admission $ Service_Date Service;
cards;
ABC   ABCD   77   5
ABC   ABCD   84   5
ABC   ABCD  100   5
ABC   ABCD  105   5
ABC   ABCD  170   6
ABC   ABCD  201   6
ABC   ABCD   82   6
ABC   ABCD  181   7
ABC   ABCD  126   7
ABC   ABCD  230   7
DEF   DEFA  77    7
DEF   DEFA  84    8
DEF   DEFA  100   13
DEF   DEFA  105   6
DEF   DEFA  170   8
DEF   DEFA  201  13
DEF   DEFA  82    5
DEF   DEFA  181   5
DEF   DEFA  126   5
DEF   DEFA  230   5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I need to add a column to the above dataset that also calculates the total visits per patient&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC&amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;DEF&amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 15:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631938#M187282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-13T15:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631957#M187293</link>
      <description>&lt;P&gt;Many thanks This works&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies i should have indicated this earlier&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i also have to seperate out the&amp;nbsp; admisions that had total visits/admission&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and greater than or equal to 3&lt;/P&gt;&lt;P&gt;How would i do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 16:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631957#M187293</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-13T16:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing and Adding a total column in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631971#M187302</link>
      <description>That's a different question entirely. Please show your input and expected output, preferably in a new question.</description>
      <pubDate>Fri, 13 Mar 2020 16:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-and-Adding-a-total-column-in-the-dataset/m-p/631971#M187302</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-13T16:45:31Z</dc:date>
    </item>
  </channel>
</rss>

