<?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: Increase count sequence when encountering a specific visit value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638527#M189886</link>
    <description>&lt;P&gt;I suspect that you want to reset the count to 0 when each USUBJID is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data endptx;
set endpt00;
by usubjid vst_num vsdat;
if first.usubjid then count=0;
if vst_num='A1' then count+1;

run;&lt;/PRE&gt;
&lt;P&gt;If that does not provide what you need then you will need to provide some example data for input and the expected output for the given example. Best is to provide the example data in the form of data step code.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 22:30:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-08T22:30:17Z</dc:date>
    <item>
      <title>Increase count sequence when encountering a specific visit value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638522#M189883</link>
      <description>&lt;H4&gt;&lt;FONT face="Segoe UI" size="4" color="#000000"&gt;Hi all!&lt;/FONT&gt;&lt;/H4&gt;
&lt;H4&gt;&lt;FONT face="Segoe UI" size="4" color="#000000"&gt;I have a counting visit question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; For ONE subject, if I had visits A1 A3 D1 LD&amp;nbsp; and again A1 A2 A3 D1&amp;nbsp; (all on different dates).&amp;nbsp; Whenever encountering 'A1', i want to increase the count variable.&lt;/FONT&gt;&lt;/H4&gt;
&lt;P&gt;&lt;FONT face="Segoe UI" size="4" color="#000000"&gt;So the sorted visits look like&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;H4&gt;&lt;FONT face="Segoe UI" size="3" color="#000000"&gt;A1 A3 D1 LD&amp;nbsp; A1 A2 A3 D1&lt;/FONT&gt;&lt;/H4&gt;
&lt;P&gt;&lt;FONT face="Segoe UI" size="4" color="#000000"&gt;and the counting sequence I want is 1 1 1 1 2 2 2 2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my failed attempt:&lt;/P&gt;
&lt;P&gt;data endptx;&lt;BR /&gt;set endpt00;&lt;BR /&gt;by usubjid vst_num vsdat;&lt;BR /&gt;count=0;&lt;BR /&gt;if vst_num='A1' then count+1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638522#M189883</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2020-04-08T22:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count sequence when encountering a specific visit value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638527#M189886</link>
      <description>&lt;P&gt;I suspect that you want to reset the count to 0 when each USUBJID is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data endptx;
set endpt00;
by usubjid vst_num vsdat;
if first.usubjid then count=0;
if vst_num='A1' then count+1;

run;&lt;/PRE&gt;
&lt;P&gt;If that does not provide what you need then you will need to provide some example data for input and the expected output for the given example. Best is to provide the example data in the form of data step code.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638527#M189886</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T22:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count sequence when encountering a specific visit value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638528#M189887</link>
      <description>&lt;P&gt;What about:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data endptx;
  set endpt00;
  by usubjid vst_num vsdat;
  if first.usubjid then count=0;
  if vst_num='A1' then count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-sequence-when-encountering-a-specific-visit-value/m-p/638528#M189887</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-04-08T22:30:35Z</dc:date>
    </item>
  </channel>
</rss>

