<?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 count the total values per group in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735487#M38593</link>
    <description>&lt;P&gt;I have a dataset which looks like below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input type $ quarter phase;
  datalines;
SS-X01 202001 1
SS-X01 202002 1
SS-X02 202001 1
SS-X02 202002 2
SS-Y02 202102 1
SS-Y02 202103 3
SS-Y01 202102 1
SS-Y01 202103 3
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm trying to do the following things:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I'm trying to calculate the total count of the phases for every quarter.&lt;/LI&gt;&lt;LI&gt;I'm trying to add (or change) the type column which selects only the values without everything that comes after the XX-LETTER.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I want my dataset to look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;type quarter phase total

SS-X 202001 1 2
SS-X 202002 1 1
SS-X 202001 2 0
SS-X 202002 2 1
SS-Y 202102 1 2
SS-Y 202103 1 0
SS-Y 202102 3 0
SS-Y 202103 3 2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Apr 2021 11:56:12 GMT</pubDate>
    <dc:creator>Andalusia</dc:creator>
    <dc:date>2021-04-20T11:56:12Z</dc:date>
    <item>
      <title>How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735487#M38593</link>
      <description>&lt;P&gt;I have a dataset which looks like below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input type $ quarter phase;
  datalines;
SS-X01 202001 1
SS-X01 202002 1
SS-X02 202001 1
SS-X02 202002 2
SS-Y02 202102 1
SS-Y02 202103 3
SS-Y01 202102 1
SS-Y01 202103 3
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm trying to do the following things:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I'm trying to calculate the total count of the phases for every quarter.&lt;/LI&gt;&lt;LI&gt;I'm trying to add (or change) the type column which selects only the values without everything that comes after the XX-LETTER.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I want my dataset to look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;type quarter phase total

SS-X 202001 1 2
SS-X 202002 1 1
SS-X 202001 2 0
SS-X 202002 2 1
SS-Y 202102 1 2
SS-Y 202103 1 0
SS-Y 202102 3 0
SS-Y 202103 3 2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 11:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735487#M38593</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T11:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735490#M38594</link>
      <description>&lt;P&gt;Do you need to do this by type? I don't completely follow your logic, please be more specific.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 11:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735490#M38594</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-20T11:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735491#M38595</link>
      <description>&lt;P&gt;I don't see how you get this result in the output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SS-Y 202102  1     2&lt;/PRE&gt;
&lt;P&gt;as I think the result ought to be a 1 in the final column for this row. Could you please explain?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 11:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735491#M38595</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T11:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735495#M38596</link>
      <description>I want to do it by quarter and type. If you look to my desired output you can see that for Type X quarter 202001 I have two 1's. And for Type Y quarter I have 202103 I have two 3's</description>
      <pubDate>Tue, 20 Apr 2021 11:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735495#M38596</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T11:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735497#M38598</link>
      <description>&lt;P&gt;That means for type Y quarter 202102 I have two 1's. Get it? Im counting how much PHASE occurs.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735497#M38598</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T12:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735498#M38599</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
    set have;
    type=substr(type,1,4);
run;
proc freq data=intermediate;
    tables type*quarter*phase/list nopercent nocum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735498#M38599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T12:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735500#M38600</link>
      <description>What does the 1,4 in your code stand for? What for example if that was 1,10?</description>
      <pubDate>Tue, 20 Apr 2021 12:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735500#M38600</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T12:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735506#M38602</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(type,1,4)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;indicates we want to take part of the value of variable TYPE ... which parts? we start at the first character and continue for until a total of four characters has been selected&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the value of TYPE is&amp;nbsp;SS-X01, then we take the first four characters, resulting in SS-X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it said substr(type,2,10), we would select the characters starting with the second character and continue until 10 characters had been selected.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735506#M38602</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T12:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735511#M38603</link>
      <description>Oke but where is the Total column? I only see the new Type column?</description>
      <pubDate>Tue, 20 Apr 2021 12:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735511#M38603</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T12:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735513#M38604</link>
      <description>&lt;P&gt;TOTAL is found in the output from PROC FREQ. I believe the default column name used in PROC FREQ is Frequency.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735513#M38604</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T12:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735516#M38605</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/STRONG&gt;Oke but this does not look the same as my desired outcome. Its just a frequency ...I also want it to be a dataset and not a report .&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andalusia_0-1618922427981.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58365i0CED880F2EEE30A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andalusia_0-1618922427981.png" alt="Andalusia_0-1618922427981.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735516#M38605</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T12:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735519#M38607</link>
      <description>&lt;P&gt;This is not the output I get. Please show the code you are using.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735519#M38607</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T12:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735533#M38609</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;This is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input type $ quarter phase;
  datalines;
SS-X01 202001 1
SS-X01 202002 1
SS-X02 202001 1
SS-X02 202002 2
SS-Y02 202102 1
SS-Y02 202103 3
SS-Y01 202102 1
SS-Y01 202103 3
;

data intermediate;
    set have;
    type=substr(type,1,4);
run;
proc freq data=intermediate;
    tables type*quarter*phase/list nopercent nocum;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is intermediate:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andalusia_0-1618923669205.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58369iAB406BC4A66A66C7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andalusia_0-1618923669205.png" alt="Andalusia_0-1618923669205.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is FREQ Procedure:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andalusia_1-1618923686699.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58370i7B021519650606EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andalusia_1-1618923686699.png" alt="Andalusia_1-1618923686699.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Two things:&lt;BR /&gt;* I want the zero frequencies also.&lt;BR /&gt;* I want it to be a dataset not a report because I need to do some other things with it after this.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735533#M38609</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T13:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735544#M38610</link>
      <description>&lt;P&gt;To create a data set, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tables type*quarter*phase/list noprint out=outputdatasetname;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain how you would know the entire set of all possible places where a zero would appear. For example, your original output has SS-X and phase 2 with Total = 0, but when you go to SS-Y there is no phase 2 with Total = 0 in the output data set. Why is that?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735544#M38610</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T13:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735554#M38611</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Oké. Can you explain your question regarding the zeros? I didn't understand it&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735554#M38611</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T13:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735556#M38612</link>
      <description>&lt;P&gt;There were two questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;"&lt;SPAN&gt;Please explain how you would know the entire set of all possible places where a zero would appear."&lt;/SPAN&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;"Your original output has SS-X and phase 2 with Total = 0, but when you go to SS-Y there is no phase 2 with Total = 0 in the output data set. Why is that?" Specifically, why is there not an output row that says&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE&gt;SS-Y 202102 2 0&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735556#M38612</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T13:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735561#M38614</link>
      <description>&lt;P&gt;Aha. I understand your questions, Its a quiet complex situation. Hope I can clarify it by this. PS. Thank you for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Answering your 1st question. There are 3 different phases which can appear in the column PHASE (1,2 and 3). There is a possibility that a certain type can contain only phase 1 and 3 (count phase 2 is automatically zero then regardless of the quarter) there is also a possibility that a type can contain phase 1,2 and 3. But there is also a possibility that a type can contain only phase 1 (which automatically means that count type 2 and 3 are zeros regardless of the quarter).&lt;BR /&gt;&lt;BR /&gt;Answering your 2nd question. The SS-Y types only contain a phase 1 and 3. So phase 2 is automatically 0. The SS-X types contains phase 1 and 2 but quarter 202001 does not contain phase 2, that's why that one contains a zero.&lt;BR /&gt;&lt;BR /&gt;Conclusion: phase 1,2 and 3 always need to be counted even if a type does not contain a certain phase.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735561#M38614</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T14:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735574#M38619</link>
      <description>&lt;P&gt;Before I put forward a solution, allow me to ask about the real data that you will be applying this to, not the 8 row data set which is clearly an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many values of TYPE (after removing the last two characters, as we are doing) and how many values of quarter? Apparently, there can be at most 3 phases.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735574#M38619</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T14:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735576#M38620</link>
      <description>&lt;P&gt;Also, do all values of QUARTER appear for all values of TYPE (after removing the last two characters)?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735576#M38620</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T14:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the total values per group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735588#M38622</link>
      <description>Oke about the real dataset. TYPE can have 4 different values. QUARTER can have 9 different values (4 per year (2019, 2020) and 1 for this year(2021).&lt;BR /&gt;&lt;BR /&gt;No, not all values of QUARTER appear for all values of TYPE. It is possible that a QUARTER occurs in TYPE X but not in TYPE Z. That means that the concerned TYPE was not measured during that quarter.&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-total-values-per-group/m-p/735588#M38622</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-20T14:43:33Z</dc:date>
    </item>
  </channel>
</rss>

