<?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: Count only all conditions are in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/823008#M324979</link>
    <description>You're right, i will post in the future datalines.&lt;BR /&gt;&lt;BR /&gt;i was adding it from my phone, that's why.&lt;BR /&gt;&lt;BR /&gt;youre solution is not that i wanted but i used it as a first step and use the outecome to count the ok and nok</description>
    <pubDate>Tue, 12 Jul 2022 20:28:32 GMT</pubDate>
    <dc:creator>Faruk</dc:creator>
    <dc:date>2022-07-12T20:28:32Z</dc:date>
    <item>
      <title>Count only all conditions are</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/822644#M324843</link>
      <description>Hi,&lt;BR /&gt;i want to count records only when all conditions of the group are match the accepted value. &lt;BR /&gt;&lt;BR /&gt;Example data :&lt;BR /&gt;&lt;BR /&gt;Car, Type, Engine, Test result &lt;BR /&gt;Honda  Civic Hybrid Ok&lt;BR /&gt;Honda Civic Benz Ok&lt;BR /&gt;Honda Civic Diesel Nok&lt;BR /&gt;Mercedes Cklass Benz Ok&lt;BR /&gt;Mercedes Cklass Hybrid Ok&lt;BR /&gt;Mercedes Cklass Diesel Ok&lt;BR /&gt;Audi a6 Benz Ok&lt;BR /&gt;Audi a6 Hybrid Ok&lt;BR /&gt;Tesla x Benz Nok&lt;BR /&gt;Tesla x Hybrid Nok&lt;BR /&gt;Tesla x Diesel Nok&lt;BR /&gt;Opel Insigne Hybrid Unknown&lt;BR /&gt;Opel Insigne Diesel Unknown&lt;BR /&gt;Opel Insigne Benz Ok&lt;BR /&gt;Volvo V60 Benz Ok&lt;BR /&gt;Volvo V60 Hybrid Nok&lt;BR /&gt;Volvo V60 Diesel Nok&lt;BR /&gt;Volvo V60 Electric Unknown&lt;BR /&gt;Peugeot 5008 Benz Unknown&lt;BR /&gt;Peugeot 5008 Hybrid Unknown&lt;BR /&gt;Peugeot 5008 Diesel Unknown&lt;BR /&gt;&lt;BR /&gt;What i want as count is that all cars with same type are counted if all the results of a car type are Ok&lt;BR /&gt;and if one of results is Nok or Unknown it counted as Nok&lt;BR /&gt;And also counted the cars an type who has Unknown as result. &lt;BR /&gt;&lt;BR /&gt;So the first group is this, &lt;BR /&gt;Honda has minimum 1 Nok so its Nok. &lt;BR /&gt;Mercedes and Audi have all the records Ok so its Ok&lt;BR /&gt;Tesla has all the records Nok&lt;BR /&gt;Opel had one result Unknown so is Unknown &lt;BR /&gt;&lt;BR /&gt;Volvo has  Unknown and  Nok so  result is Unknown and nok&lt;BR /&gt;And Peugeot  has all records Unknown &lt;BR /&gt;&lt;BR /&gt;Car, Type, Engine, Passed, Count&lt;BR /&gt;Honda  Civic  Nok &lt;BR /&gt;Mercedes Cklass Ok &lt;BR /&gt;Audi a6 Benz Ok&lt;BR /&gt;Tesla x Benz Nok&lt;BR /&gt;Opel Insigne Hybrid Unknown&lt;BR /&gt;Volvo V60 Nok&lt;BR /&gt;Volvo V60 Unknown&lt;BR /&gt;Peugeot 5008 Benz Unknown&lt;BR /&gt;&lt;BR /&gt;So accepted end solution is:&lt;BR /&gt;Cars that are Ok: 2&lt;BR /&gt;Cars that are Nok: 3&lt;BR /&gt;Cars that also are Unknown: 2&lt;BR /&gt;&lt;BR /&gt;Total car type that are tested: 7&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jul 2022 19:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/822644#M324843</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-07-11T19:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count only all conditions are</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/822770#M324881</link>
      <description>&lt;P&gt;You will have a much better chance of getting an answer if you present your data as a data step, e.g. 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 Car $ Type $ Engine $ Test_result $;
cards;
Honda Civic Hybrid Ok
Honda Civic Benz Ok
Honda Civic Diesel Nok
Mercedes Cklass Benz Ok
Mercedes Cklass Hybrid Ok
Mercedes Cklass Diesel Ok
Audi a6 Benz Ok
Audi a6 Hybrid Ok
Tesla x Benz Nok
Tesla x Hybrid Nok
Tesla x Diesel Nok
Opel Insigne Hybrid Unknown
Opel Insigne Diesel Unknown
Opel Insigne Benz Ok
Volvo V60 Benz Ok
Volvo V60 Hybrid Nok
Volvo V60 Diesel Nok
Volvo V60 Electric Unknown
Peugeot 5008 Benz Unknown
Peugeot 5008 Hybrid Unknown
Peugeot 5008 Diesel Unknown
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think you can get the answers you want like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by car type notsorted;
  n_OK+Test_result='Ok';
  n_Nok+Test_result='Nok';
  n_Unknown+Test_result='Unknown';
  if last.type;
  if n_Nok then do;
    Test_result='Nok';
    output;
    if n_Unknown then do;
      Test_result='Unknown';
      output;
      end;
    end;
  else if n_Unknown then do;
    Test_result='Unknown';
    output;
    end;
  else do;
    Test_result='Ok';
    output;
    end;  
  call missing(of n_:);
  drop engine;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Your input data is grouped, but not sorted by CAR and TYPE. So I took the lazy way out and set it BY CAR TYPE NOTSORTED, instead of sorting before the second step. With real life data you may want to sort.&lt;/LI&gt;
&lt;LI&gt;The SUM statements (e.g. &lt;CODE class=" language-sas"&gt;n_OK+Test_result='Ok'&lt;/CODE&gt;) automatically retain the result variables.&lt;/LI&gt;
&lt;LI&gt;So when we reach the final car for a given TYPE, the counts of the test results are in the 3 summary variables&lt;/LI&gt;
&lt;LI&gt;After outputting the results, the summary variables are set to missing&lt;/LI&gt;
&lt;LI&gt;The ENGINE variable is not relevant for the output, and varies over CAR and TYPE, so I dropped that for the final output.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;But I do not think your specification of results is consistent. On one hand, your output table has two records for the Volvo, but&amp;nbsp; in the final sum-up you apparently only count the "Nok" record (otherwise, there should be 3 types that are "also Unknown").&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 07:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/822770#M324881</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-07-12T07:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count only all conditions are</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/823008#M324979</link>
      <description>You're right, i will post in the future datalines.&lt;BR /&gt;&lt;BR /&gt;i was adding it from my phone, that's why.&lt;BR /&gt;&lt;BR /&gt;youre solution is not that i wanted but i used it as a first step and use the outecome to count the ok and nok</description>
      <pubDate>Tue, 12 Jul 2022 20:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-only-all-conditions-are/m-p/823008#M324979</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-07-12T20:28:32Z</dc:date>
    </item>
  </channel>
</rss>

