<?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: Detect a sequential jump in a character field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/721206#M223493</link>
    <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370510"&gt;@nanmz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;why did you create temporary variables in order to get the desired output?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good question. My previous approach was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_i);
set have;
flag=0;
do _i=2 to length(x);
  if abs(input(char(x,_i),1.)-input(char(x,_i-1),1.))&amp;gt;1 then do;
    flag=1;
    leave;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Obviously, this is simpler code. What I didn't like about it was that it extracts most of the digits &lt;EM&gt;twice&lt;/EM&gt;. More precisely: For a digit string of length &lt;EM&gt;n&lt;/EM&gt; it evaluates &lt;STRONG&gt;&lt;EM&gt;2n−2&lt;/EM&gt;&lt;/STRONG&gt; expressions of the form &lt;FONT face="courier new,courier"&gt;input(char(...)...)&lt;/FONT&gt;, as opposed to &lt;EM&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/EM&gt; with the version using the temporary array. So, the intention was to provide (hopefully) more efficient code, but I haven't measured its performance yet. Of course, if your HAVE dataset is small and the strings are short, there will be no significant performance difference, if any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 08:17:20 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-02-23T08:17:20Z</dc:date>
    <item>
      <title>Detect a sequential jump in a character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720873#M223345</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character variable that looks like this:&lt;/P&gt;&lt;P&gt;var x&lt;/P&gt;&lt;P&gt;004101010100100111121001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;122112102102111111212112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;111011111111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;111112111111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;000043211111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;reading it from left to right, my main aim is to flag (0 or 1) for accounts that has the varx that are NOT in sequential order as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var x&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;004101010100100111121001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;122112102102111111212112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;BR /&gt;111011111111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;111112111111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;&lt;STRONG&gt;000043211111111111111111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you guys have any idea of how I can do this? Appreciate the help. Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 11:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720873#M223345</guid>
      <dc:creator>nanmz</dc:creator>
      <dc:date>2021-02-22T11:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Detect a sequential jump in a character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720875#M223346</link>
      <description>&lt;P&gt;Define sequential order please?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 11:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720875#M223346</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-22T11:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Detect a sequential jump in a character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720891#M223352</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370510"&gt;@nanmz&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If "jumps" by more than 1 &lt;EM&gt;in either direction&lt;/EM&gt; are to be flagged, try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $50.;
cards;
004101010100100111121001
122112102102111111212112
111011111111111111111111
111112111111111111111111
000043211111111111111111
;

data want(drop=_i);
set have;
flag=0;
array _d[0:1] _temporary_;
_d[1]=input(char(x,1),1.);
do _i=2 to length(x);
  _d[mod(_i,2)]=input(char(x,_i),1.);
  if abs(_d[1]-_d[0])&amp;gt;1 then do;
    flag=1;
    leave;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 12:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/720891#M223352</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-22T12:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Detect a sequential jump in a character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/721170#M223470</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_blank" rel="noopener"&gt;FreelanceReinhard&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This worked out great btw! Many thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having said that, I'm just trying to understand the logic of the code a bit better.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;_d[0:1] _temporary_;
_d[1]=input(char(x,1),1.);
do _i=2 to length(x);
  _d[mod(_i,2)]=input(char(x,_i),1.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;why did you create temporary variables in order to get the desired output? Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/721170#M223470</guid>
      <dc:creator>nanmz</dc:creator>
      <dc:date>2021-02-23T02:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Detect a sequential jump in a character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/721206#M223493</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370510"&gt;@nanmz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;why did you create temporary variables in order to get the desired output?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good question. My previous approach was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_i);
set have;
flag=0;
do _i=2 to length(x);
  if abs(input(char(x,_i),1.)-input(char(x,_i-1),1.))&amp;gt;1 then do;
    flag=1;
    leave;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Obviously, this is simpler code. What I didn't like about it was that it extracts most of the digits &lt;EM&gt;twice&lt;/EM&gt;. More precisely: For a digit string of length &lt;EM&gt;n&lt;/EM&gt; it evaluates &lt;STRONG&gt;&lt;EM&gt;2n−2&lt;/EM&gt;&lt;/STRONG&gt; expressions of the form &lt;FONT face="courier new,courier"&gt;input(char(...)...)&lt;/FONT&gt;, as opposed to &lt;EM&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/EM&gt; with the version using the temporary array. So, the intention was to provide (hopefully) more efficient code, but I haven't measured its performance yet. Of course, if your HAVE dataset is small and the strings are short, there will be no significant performance difference, if any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 08:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-a-sequential-jump-in-a-character-field/m-p/721206#M223493</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-23T08:17:20Z</dc:date>
    </item>
  </channel>
</rss>

