<?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 Assign incremental category based on a pre-specified sort by a discrete variable which value repeat in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844477#M82278</link>
    <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following scenario:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The raw data has a seqoccur to indicate the order in which it happened and cannot be changed. The type variable indicates what happened among to only possibilities.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rawdata;&lt;BR /&gt;input seqoccur 1-2 type $ 3-13;&lt;BR /&gt;cards;&lt;BR /&gt;1 CONTINUOUS&lt;BR /&gt;2 CONTINUOUS&lt;BR /&gt;3 BROKEN&lt;BR /&gt;4 BROKEN&lt;BR /&gt;5 BROKEN&lt;BR /&gt;6 BROKEN&lt;BR /&gt;7 CONTINUOUS&lt;BR /&gt;8 CONTINUOUS&lt;BR /&gt;9 CONTINUOUS&lt;BR /&gt;10 CONTINUOUS&lt;BR /&gt;11 CONTINUOUS&lt;BR /&gt;12 BROKEN&lt;BR /&gt;13 CONTINUOUS&lt;BR /&gt;14 BROKEN&lt;BR /&gt;15 BROKEN&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To this, in the variable I call 'grouptype' I need to assign a value incrementally as below, i.e. repeating within the first type of occurrence and incrementing by the next occurrence and the number doesn't change until the next occurrence. I've tried the usual sort/retain/first.variable techniques but none I know gives the result as below in "grouptype".&amp;nbsp; Any suggestions?&amp;nbsp; many thanks!&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input seqoccur 1-2 type $ 3-13 grouptype 14-15;&lt;BR /&gt;cards;&lt;BR /&gt;1 CONTINUOUS 1&lt;BR /&gt;2 CONTINUOUS 1&lt;BR /&gt;3 BROKEN 2&lt;BR /&gt;4 BROKEN 2&lt;BR /&gt;5 BROKEN 2&lt;BR /&gt;6 BROKEN 2&lt;BR /&gt;7 CONTINUOUS 3&lt;BR /&gt;8 CONTINUOUS 3&lt;BR /&gt;9 CONTINUOUS 3&lt;BR /&gt;10 CONTINUOUS 3&lt;BR /&gt;11 CONTINUOUS 3&lt;BR /&gt;12 BROKEN 4&lt;BR /&gt;13 CONTINUOUS 5&lt;BR /&gt;14 BROKEN 6&lt;BR /&gt;15 BROKEN 6&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 20:04:38 GMT</pubDate>
    <dc:creator>Karolus</dc:creator>
    <dc:date>2022-11-15T20:04:38Z</dc:date>
    <item>
      <title>Assign incremental category based on a pre-specified sort by a discrete variable which value repeat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844477#M82278</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following scenario:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The raw data has a seqoccur to indicate the order in which it happened and cannot be changed. The type variable indicates what happened among to only possibilities.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rawdata;&lt;BR /&gt;input seqoccur 1-2 type $ 3-13;&lt;BR /&gt;cards;&lt;BR /&gt;1 CONTINUOUS&lt;BR /&gt;2 CONTINUOUS&lt;BR /&gt;3 BROKEN&lt;BR /&gt;4 BROKEN&lt;BR /&gt;5 BROKEN&lt;BR /&gt;6 BROKEN&lt;BR /&gt;7 CONTINUOUS&lt;BR /&gt;8 CONTINUOUS&lt;BR /&gt;9 CONTINUOUS&lt;BR /&gt;10 CONTINUOUS&lt;BR /&gt;11 CONTINUOUS&lt;BR /&gt;12 BROKEN&lt;BR /&gt;13 CONTINUOUS&lt;BR /&gt;14 BROKEN&lt;BR /&gt;15 BROKEN&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To this, in the variable I call 'grouptype' I need to assign a value incrementally as below, i.e. repeating within the first type of occurrence and incrementing by the next occurrence and the number doesn't change until the next occurrence. I've tried the usual sort/retain/first.variable techniques but none I know gives the result as below in "grouptype".&amp;nbsp; Any suggestions?&amp;nbsp; many thanks!&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input seqoccur 1-2 type $ 3-13 grouptype 14-15;&lt;BR /&gt;cards;&lt;BR /&gt;1 CONTINUOUS 1&lt;BR /&gt;2 CONTINUOUS 1&lt;BR /&gt;3 BROKEN 2&lt;BR /&gt;4 BROKEN 2&lt;BR /&gt;5 BROKEN 2&lt;BR /&gt;6 BROKEN 2&lt;BR /&gt;7 CONTINUOUS 3&lt;BR /&gt;8 CONTINUOUS 3&lt;BR /&gt;9 CONTINUOUS 3&lt;BR /&gt;10 CONTINUOUS 3&lt;BR /&gt;11 CONTINUOUS 3&lt;BR /&gt;12 BROKEN 4&lt;BR /&gt;13 CONTINUOUS 5&lt;BR /&gt;14 BROKEN 6&lt;BR /&gt;15 BROKEN 6&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 20:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844477#M82278</guid>
      <dc:creator>Karolus</dc:creator>
      <dc:date>2022-11-15T20:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Assign incremental category based on a pre-specified sort by a discrete variable which value rep</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844478#M82279</link>
      <description>p.s. apologies for the typos , I meant "among two only possibilities"</description>
      <pubDate>Tue, 15 Nov 2022 20:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844478#M82279</guid>
      <dc:creator>Karolus</dc:creator>
      <dc:date>2022-11-15T20:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign incremental category based on a pre-specified sort by a discrete variable which value rep</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844479#M82280</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawdata;
input seqoccur 1-2 type $ 3-13;
cards;
1 CONTINUOUS
2 CONTINUOUS
3 BROKEN
4 BROKEN
5 BROKEN
6 BROKEN
7 CONTINUOUS
8 CONTINUOUS
9 CONTINUOUS
10 CONTINUOUS
11 CONTINUOUS
12 BROKEN
13 CONTINUOUS
14 BROKEN
15 BROKEN
;
run;

data want;
   set rawdata;
   by type notsorted;
   if first.type then grouptype + 1;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;seqoccur  type        grouptype
1         CONTINUOUS  1
2         CONTINUOUS  1
3         BROKEN      2
4         BROKEN      2
5         BROKEN      2
6         BROKEN      2
7         CONTINUOUS  3
8         CONTINUOUS  3
9         CONTINUOUS  3
10        CONTINUOUS  3
11        CONTINUOUS  3
12        BROKEN      4
13        CONTINUOUS  5
14        BROKEN      6
15        BROKEN      6&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 20:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844479#M82280</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-15T20:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign incremental category based on a pre-specified sort by a discrete variable which value rep</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844498#M82282</link>
      <description>&lt;P&gt;oh my, of course,&amp;nbsp; a very forgotten option, 'by notsorted'.&amp;nbsp; A millions thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 21:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-incremental-category-based-on-a-pre-specified-sort-by-a/m-p/844498#M82282</guid>
      <dc:creator>Karolus</dc:creator>
      <dc:date>2022-11-15T21:23:12Z</dc:date>
    </item>
  </channel>
</rss>

