<?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 number of condition met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164447#M300357</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure why you tried an approach by making copies of the original files, then transposing them, and then trying to obtain the desired results.&amp;nbsp; One of your data steps wouldn't even run as you had used first.id without ever including a by id statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the reason I used if _n_ eq 1 to set filter was so that SAS wouldn't stop reading records after it read the one record in the filter data set.&amp;nbsp; With the 'if _n_ eq 1 then' condition established, SAS will happily read all of the records from original.&amp;nbsp; That was the reason why your original attempt only read one record.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Dec 2013 17:55:51 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2013-12-05T17:55:51Z</dc:date>
    <item>
      <title>Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164442#M300352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following problem and cannot fully solve. Please help me if you could.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 2 data set: (a) original with f1-f4 variables with many records and (b) filter which show 1 condition/value for f1 f2 f4 &lt;/P&gt;&lt;P&gt;I want to create a new column "number" in the original file to count the number of time a given variable in original data has the same value as stated in filter file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the below example, the first record should has "number"= 3 as f1 f2 f4 match value in filter.&lt;/P&gt;&lt;P&gt;second record should has "number"=2 (f1 f2)&lt;/P&gt;&lt;P&gt;third record should has "number"=1 (f1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I try to write a code but somehow the output file only has 1 record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me with my code or create a new one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data originial;&lt;/P&gt;&lt;P&gt;input id f1 f2 f3 f4 ;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 0 1 2 4&lt;/P&gt;&lt;P&gt;2 0 1 4 6&lt;/P&gt;&lt;P&gt;3 0 8 6 9&lt;/P&gt;&lt;P&gt;4 1 3 6 8&lt;/P&gt;&lt;P&gt;5 8 6 5 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data filter;&lt;/P&gt;&lt;P&gt;input f1 f2 f4;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0 1 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;set originial;&lt;/P&gt;&lt;P&gt;array ori{4} f1 f2 f3 f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; number=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set filter ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array fil{3} f1 f2 f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if vname(ori{i})=vname(fil{j}) and ori{i}=fil{j} then do; number=number+1;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 03:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164442#M300352</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-12-05T03:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164443#M300353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that the following does what you want but, if I correctly understand what you are trying to do, the second record should get a number result of 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 then set filter (rename=(f1=_f1 f2=_f2 f4=_f4)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array ori{4} f1 f2 f3 f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; number=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array fil{3} _f1 _f2 _f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set originial;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; test=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fil{i} eq (ori{j}) then test=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if test then number+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 04:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164443#M300353</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-12-05T04:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164444#M300354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Arthur for your help.&lt;/P&gt;&lt;P&gt;I am still trying to follow your code.&lt;/P&gt;&lt;P&gt;For the second record, as f1=0, f2=1 and &lt;STRONG&gt;f4=6&lt;/STRONG&gt; and filter is f1=0, f2=1 and &lt;STRONG&gt;f4=4&lt;/STRONG&gt; , only 2 condition met and number should be 2.&lt;/P&gt;&lt;P&gt;I think in IF statement, we still need condition of Name variable = Name variable vname(ori{i})=vname(fil{j}&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 04:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164444#M300354</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-12-05T04:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164445#M300355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I apparently misunderstood what you are trying to do.&amp;nbsp; If both the variables and values have to be the same, then you might be looking for something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 then set filter (rename=(f1=_f1 f2=_f2 f4=_f4)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array ori{3} f1 f2 f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array fil{3} _f1 _f2 _f4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set originial;&lt;/P&gt;&lt;P&gt;&amp;nbsp; number=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _n_=1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fil{_n_} eq (ori{_n_}) then number=number+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 13:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164445#M300355</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-12-05T13:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164446#M300356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Arthur.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I follow your approach and eventually, I make a transpose dataset to record the filter. So I can just do i=1 to N.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;By the way, I am not clear how SAS read "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; if _n_ eq 1 then set filter&lt;/SPAN&gt;"&amp;nbsp; vs&amp;nbsp; "set filter". Could you tell me why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Many thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;HHC&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data originial;&lt;/P&gt;&lt;P&gt;input id f1 f2 f3 f4 ;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 0 1 2 99&lt;/P&gt;&lt;P&gt;2 0 1 4 6&lt;/P&gt;&lt;P&gt;3 0 8 6 7&lt;/P&gt;&lt;P&gt;4 1 3 6 8&lt;/P&gt;&lt;P&gt;5 9 9 9 9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data filter;&lt;/P&gt;&lt;P&gt;input f1 f2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data ff; set originial;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data ff; set ff filter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop id;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc transpose data=ff out=f3;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data f3; set f3; drop _name_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc transpose data=f3 out=f4;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data f4; set f4;drop _name_;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*-----------------------------------------------------------;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 then set f4; &lt;/P&gt;&lt;P&gt;&amp;nbsp; number=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array fil{4} col1-col4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set originial;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array ori{4} f1 f2 f3 f4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; test=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fil{i} eq (ori{i}) then NUMBER=NUMBER+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;*-----------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 17:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164446#M300356</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-12-05T17:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164447#M300357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure why you tried an approach by making copies of the original files, then transposing them, and then trying to obtain the desired results.&amp;nbsp; One of your data steps wouldn't even run as you had used first.id without ever including a by id statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the reason I used if _n_ eq 1 to set filter was so that SAS wouldn't stop reading records after it read the one record in the filter data set.&amp;nbsp; With the 'if _n_ eq 1 then' condition established, SAS will happily read all of the records from original.&amp;nbsp; That was the reason why your original attempt only read one record.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 17:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164447#M300357</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-12-05T17:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164448#M300358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your help, Arthur.&lt;/P&gt;&lt;P&gt;The reason I did it is that there are about 100 condition and I dont want to manually count the position to put in DO statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 03:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-condition-met/m-p/164448#M300358</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-12-06T03:17:41Z</dc:date>
    </item>
  </channel>
</rss>

