<?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 variable with condition and assign to the max value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562712#M157656</link>
    <description>&lt;P&gt;Your &lt;STRONG&gt;day&amp;nbsp;&lt;/STRONG&gt;variable is not the same in your two data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you can do 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 id $ day;
datalines;
A   7
A   4
A   5
B   4
B   1
B   7
B   3
C   7
C   1
C   6
D   2
D   3
D   7
E   2
E   2
E   3
E   4
;

data want;
   N_day=0;
   do until (last.id);
      set have;
      by id;
      if day in (1, 6, 7) then N_day=N_day+1;
   end;
   do until (last.id);
      set have;
      by id;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 May 2019 20:31:52 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-05-30T20:31:52Z</dc:date>
    <item>
      <title>count variable with condition and assign to the max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562708#M157652</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;Hi&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have a SAS question and would like to have your help.&amp;nbsp; I need to create a count variable when the day variable is in (1,6,7) per ID, and then assign that count variable to the max value. The order cannot be changed. For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&amp;nbsp;4&amp;nbsp; &amp;nbsp;0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you for your help.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 30 May 2019 20:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562708#M157652</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2019-05-30T20:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: count variable with condition and assign to the max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562710#M157654</link>
      <description>&lt;P&gt;Why does the count increase by 1 at this line?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 20:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562710#M157654</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-05-30T20:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: count variable with condition and assign to the max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562712#M157656</link>
      <description>&lt;P&gt;Your &lt;STRONG&gt;day&amp;nbsp;&lt;/STRONG&gt;variable is not the same in your two data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you can do 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 id $ day;
datalines;
A   7
A   4
A   5
B   4
B   1
B   7
B   3
C   7
C   1
C   6
D   2
D   3
D   7
E   2
E   2
E   3
E   4
;

data want;
   N_day=0;
   do until (last.id);
      set have;
      by id;
      if day in (1, 6, 7) then N_day=N_day+1;
   end;
   do until (last.id);
      set have;
      by id;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 20:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-variable-with-condition-and-assign-to-the-max-value/m-p/562712#M157656</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-30T20:31:52Z</dc:date>
    </item>
  </channel>
</rss>

