<?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: Counting in SAS with multiple conditions by group in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944394#M42432</link>
    <description>&lt;P&gt;Your code doesn't create the data set properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1726663386938.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100473i7971E384DD1F911F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaigeMiller_0-1726663386938.png" alt="PaigeMiller_0-1726663386938.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 12:43:17 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-09-18T12:43:17Z</dc:date>
    <item>
      <title>Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944385#M42428</link>
      <description>&lt;P&gt;Hello group!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset with the following variables: Animal date_of_service type_of_service and type_of_diagnostic.&lt;/P&gt;&lt;P&gt;I want to do by animal:&lt;BR /&gt;count since the first type_of_diagnostic="Negative" (here the type of service can be natural or insemination), how many observations fulfilling these conditions: type_of_service="Natural" and type_of_diagnostic="Negative" until the first type_of_diagnostic being "positive".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Animal date_of_service type_of_service type_of_diagnostic&lt;BR /&gt;1 07/06/2021 Natural Negative&lt;BR /&gt;1 01/10/2021 Insemination Negative&lt;BR /&gt;1 12/01/2022 Natural Negative&lt;BR /&gt;1 03/02/2022 Insemination Negative&lt;BR /&gt;1 01/03/2022 Natural Positive&lt;/P&gt;&lt;P&gt;Results wanted:&lt;BR /&gt;Animal count&lt;BR /&gt;1 1&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 11:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944385#M42428</guid>
      <dc:creator>Chira85</dc:creator>
      <dc:date>2024-09-18T11:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944390#M42430</link>
      <description>&lt;P&gt;Please, from now on present data as WORKING data step code, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Animal date_of_service :ddmmyy10. type_of_service :$12. type_of_diagnostic $;
cards;
1 07/06/2021 Natural Negative
1 01/10/2021 Insemination Negative
1 12/01/2022 Natural Negative
1 03/02/2022 Insemination Negative
1 01/03/2022 Natural Positive
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem statement isn't particularly clear. Do you want a count of the number of animals that meet this condition, as your output appears to be showing? Or do you want, as you said, "&lt;SPAN&gt;how many observations fulfilling these conditions". Please clarify this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Furthermore, to improve the presentation of the problem and help us find a correct solution, please keep in mind these important items&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When you show the desired output, you need to show the desired output for this input data. The answer, if I am understanding you properly, cannot be 11 for this input data.&lt;/LI&gt;
&lt;LI&gt;If DATE_OF_SERVICE is not needed, don't include it.&lt;/LI&gt;
&lt;LI&gt;If the real data can have more than 1 animal, please provide sample data and output for the case where there are at least two animals.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944390#M42430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-18T12:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944393#M42431</link>
      <description>&lt;P&gt;I am sorry for the errors. The data set has more than one animal and I want to count for each animal, how many observations&amp;nbsp;&lt;SPAN&gt;fulfilling these conditions. Below is the corrected code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input Animal type_of_service $14. type_of_diagnostic $12.;
cards;
1 Natural Negative
1 Insemination Negative
1 Natural Negative
1 Insemination Negative
1 Natural Positive
2 Insemination Negative
2 Natural Negative       
2 Natural Negative
2 Insemination Positive
;
run;

Results wanted:
Animal count
1       1
2       2&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944393#M42431</guid>
      <dc:creator>Chira85</dc:creator>
      <dc:date>2024-09-18T12:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944394#M42432</link>
      <description>&lt;P&gt;Your code doesn't create the data set properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1726663386938.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100473i7971E384DD1F911F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaigeMiller_0-1726663386938.png" alt="PaigeMiller_0-1726663386938.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944394#M42432</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-18T12:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944399#M42435</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input Animal type_of_service :$12. type_of_diagnostic $12.;
cards;
1 Natural Negative
1 Insemination Negative
1 Natural Negative
1 Insemination Negative
1 Natural Positive
2 Insemination Negative
2 Natural Negative       
2 Natural Negative
2 Insemination Positive
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944399#M42435</guid>
      <dc:creator>Chira85</dc:creator>
      <dc:date>2024-09-18T12:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944400#M42436</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by animal;
    if first.animal then do;
        count=0;
        begin_count=0;
        stop_count=0;
    end;
    if type_of_diagnostic='Negative' then begin_count=1;
    if begin_count and not stop_count and type_of_service='Natural' and type_of_diagnostic='Negative' then count+1;
    if type_of_diagnostic='Positive' then stop_count=1;
    if last.animal then output;
    keep animal count;
run;     &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 13:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944400#M42436</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-18T13:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Counting in SAS with multiple conditions by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944404#M42437</link>
      <description>&lt;PRE class=""&gt;&lt;SPAN class=""&gt;I have tried it and it works. Thank you very much!&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 13:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-in-SAS-with-multiple-conditions-by-group/m-p/944404#M42437</guid>
      <dc:creator>Chira85</dc:creator>
      <dc:date>2024-09-18T13:09:05Z</dc:date>
    </item>
  </channel>
</rss>

