<?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: Add Sequence according to conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813597#M321132</link>
    <description>I want seq variable to get change when unscheduled visit is there...otherwise it should do +1 always.</description>
    <pubDate>Mon, 16 May 2022 20:39:53 GMT</pubDate>
    <dc:creator>gahlot1999</dc:creator>
    <dc:date>2022-05-16T20:39:53Z</dc:date>
    <item>
      <title>Add Sequence according to conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813592#M321131</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;My source data is -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gahlot1999_0-1652732566507.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71486i8788FD1FF18A9DB9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gahlot1999_0-1652732566507.png" alt="gahlot1999_0-1652732566507.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And I want this output -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gahlot1999_1-1652732645715.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71487iEDD559E5B307EBA2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gahlot1999_1-1652732645715.png" alt="gahlot1999_1-1652732645715.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any easy way to do this in proc sql?&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 20:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813592#M321131</guid>
      <dc:creator>gahlot1999</dc:creator>
      <dc:date>2022-05-16T20:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Add Sequence according to conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813597#M321132</link>
      <description>I want seq variable to get change when unscheduled visit is there...otherwise it should do +1 always.</description>
      <pubDate>Mon, 16 May 2022 20:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813597#M321132</guid>
      <dc:creator>gahlot1999</dc:creator>
      <dc:date>2022-05-16T20:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add Sequence according to conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813601#M321133</link>
      <description>&lt;P&gt;I imagine one could develop some way to torture SQL into submission for this task - although I am unable to see how.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why?&amp;nbsp; The DATA step cares about the sequence of incoming records, while SQL doesn't - that's SQL's advantage/disadvantage. True, in SQL you could detect "Screen","Week 1", "Week 2", "Week 3" and "End of study" to generate codes, 1,2,3,4 and 5. That's assuming you want those codes for each visit type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what about "Unscheduled?"&amp;nbsp; &amp;nbsp;Could such a record fall between "Week 2 and "Week 3", implying codes of 3.1, 3.2, etc instead of 4.1, 4.2?&amp;nbsp; How would SQL determine where the Unscheduled appears?&amp;nbsp; And then you have demonstrated the problem of multiple Unscheduled records.&amp;nbsp; Which one gets 4.1 and which gets 4.2 (assuming you even know they should be a 4.x to begin with).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This data step is untested, in the absence of sample data in the form of a working data step:&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 id;
  if seq='Unscheduled' then seq+0.1;
  else seq=ceil(seq+0.01);
  if first.id then seq=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, this assumes you never have more then 9 consecutive "Unscheduled" records.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 20:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-Sequence-according-to-conditions/m-p/813601#M321133</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-16T20:58:04Z</dc:date>
    </item>
  </channel>
</rss>

