<?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: Non-consecutive Integer Ranges Within Single Column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520979#M141321</link>
    <description>&lt;P&gt;This worked perfectly and the output is clean.&amp;nbsp; It seems my questions are slowly becoming a bit more difficult.&amp;nbsp; I look forward to the day when I can contribute as much as I ask.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2018 20:17:14 GMT</pubDate>
    <dc:creator>jawhitmire</dc:creator>
    <dc:date>2018-12-12T20:17:14Z</dc:date>
    <item>
      <title>Non-consecutive Integer Ranges Within Single Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520960#M141311</link>
      <description>&lt;P&gt;Current version: 9.04.01M5P091317&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find the non-consecutive integer ranges for a single column variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input batchno;
datalines;
375
376
377
388
980
981
982
983
2008
2009
2010
;
run;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should provide beginning and ending values within each consecutive range.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is, the output is a list of the following values for the input dataset shown above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;375&lt;/P&gt;&lt;P&gt;388&lt;/P&gt;&lt;P&gt;980&lt;/P&gt;&lt;P&gt;983&lt;/P&gt;&lt;P&gt;2008&lt;/P&gt;&lt;P&gt;2010&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520960#M141311</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2018-12-12T19:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Non-consecutive Integer Ranges Within Single Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520968#M141314</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248885"&gt;@jawhitmire&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;375&lt;/P&gt;
&lt;P&gt;388&amp;nbsp; /*is this correct or should it be 378?*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apologies if i am asking a dumb question plz&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520968#M141314</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-12T19:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Non-consecutive Integer Ranges Within Single Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520971#M141317</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Going with my assumption  378 is what to be in place instead of 388*/

data have;
infile datalines missover; 
input batchno; 
datalines; 
375 
376 
377 
378
980
981
982 
983
2008 
2009
2010
;
run;

data temp;
set have;
k=dif(batchno);
if k ne 1 then grp+1;
drop k;
run;
data want;
set temp;
by grp;
if first.grp or last.grp;
drop grp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520971#M141317</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-12T19:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Non-consecutive Integer Ranges Within Single Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520972#M141318</link>
      <description>&lt;P&gt;You need&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A way to compare current batchno to the prior batchno.&amp;nbsp; If the prior batchno is not current-batchno minus 1, then the record-in-hand is a new START.&lt;/LI&gt;
&lt;LI&gt;A way to compare current batchno to the following batchno.&amp;nbsp; If they are not different by exactly 1, then&amp;nbsp;the record-in hand is a new END.&lt;/LI&gt;
&lt;LI&gt;Only when you have an END value do you output the start/end pair.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input batchno;
datalines;
375
376
377
388
980
981
982
983
2008
2009
2010
run;

data want (keep=start end);
  merge have have (firstobs=2 keep=batchno rename=(batchno=nxt_batchno));
  if batchno-1^=lag(batchno) then start=batchno;
  retain start;
  if batchno+1^=nxt_batchno;
  end=batchno;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comparing the current to the prior (lag(batchno)) is relatively intuitive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comparing to the next can't rely on the lag function, so you need a way to read in 2 records at a time: the current record and the following record.&amp;nbsp; Since they have the same variable, you have to rename one of them.&amp;nbsp; Then do the comparison ("if batchno+1 ^= nxt_batchno;").&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520972#M141318</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-12T19:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Non-consecutive Integer Ranges Within Single Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520979#M141321</link>
      <description>&lt;P&gt;This worked perfectly and the output is clean.&amp;nbsp; It seems my questions are slowly becoming a bit more difficult.&amp;nbsp; I look forward to the day when I can contribute as much as I ask.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 20:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-consecutive-Integer-Ranges-Within-Single-Column/m-p/520979#M141321</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2018-12-12T20:17:14Z</dc:date>
    </item>
  </channel>
</rss>

