<?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: Finding correct time range in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687669#M37136</link>
    <description>&lt;P&gt;As pdct 3 only&amp;nbsp; has one week sequence, as week 5, 6, 7 and 8, whe use date_start from first row and date_end from last row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;st1   - ct1  - cr1  -  pdct3  -   5  -    11/1    -    20/2    
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1    -    30/2    
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1    -    10/3    
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1    -    20/3 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:16:51 GMT</pubDate>
    <dc:creator>carloshmcaldas</dc:creator>
    <dc:date>2020-09-29T22:16:51Z</dc:date>
    <item>
      <title>Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687362#M37120</link>
      <description>&lt;P&gt;Hi folks, I'm trying to identify the time range from a database and I don't know how to do it at SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how my database is:&lt;/P&gt;&lt;PRE&gt;state - city - crop - product - week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1    -    31/1    
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12    -   10/12    
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12    -   31/12    
st1   - ct1  - cr1  -  pdct2  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct2  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct2  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct2  -  36  -   21/12    -   31/12    
st1   - ct1  - cr1  -  pdct3  -   5  -    11/1    -    20/2    
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1    -    30/2    
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1    -    10/3    
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1    -    20/3    &lt;/PRE&gt;&lt;P&gt;I need identify the date that a crop planting starts and when it ends. The issue that some crops plantation starts in one year and ends at the next year. So, my database output should be like this, but didn't figure how to do this on SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;state - city - crop - product - date_start -  date_end 
st1   - ct1  - cr1  -  pdct1  -    1/12    -    31/1    
st1   - ct1  - cr1  -  pdct2  -   11/12    -    20/1        
st1   - ct1  - cr1  -  pdct3  -    11/1    -    20/3    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ps. Sorry for my bad english.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 22:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687362#M37120</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-28T22:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687381#M37122</link>
      <description>&lt;P&gt;Are your dates truly just character values like&lt;/P&gt;
&lt;PRE&gt; 1/12 &lt;/PRE&gt;
&lt;P&gt;or are they a DATE or DATETIME value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 01:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687381#M37122</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T01:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687383#M37123</link>
      <description>Date, with dd/mm format</description>
      <pubDate>Tue, 29 Sep 2020 01:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687383#M37123</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-29T01:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687387#M37125</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349660"&gt;@carloshmcaldas&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be possible for you to provide me with real dates, either in SAS date format or in a character format that SAS can read like 2020-09-28.&amp;nbsp; Take a look at the code below.&amp;nbsp; Can you change it to give me real dates to work with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Crop_Data;
	INFILE	DATALINES4
			DSD	DLM='-'
			FIRSTOBS=2
			;
	
	INPUT	State		:	$3.
			City		:	$3.
			Crop		:	$3.
			Product		:	$5.
			Week		:	$2.
			Date_Start	:	$5.
			Date_End	:	$5.
			;

DATALINES4;
state - city - crop - product - week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1    -    31/1    
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12    -   10/12    
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12    -   31/12    
st1   - ct1  - cr1  -  pdct2  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct2  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct2  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct2  -  36  -   21/12    -   31/12    
st1   - ct1  - cr1  -  pdct3  -   5  -    11/1    -    20/2    
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1    -    30/2    
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1    -    10/3    
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1    -    20/3  
;;;;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code gives me the below results, but I need real dates in order to try to solve the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601344419722.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49914i09BAB51FBC5363F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601344419722.png" alt="jimbarbour_0-1601344419722.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 01:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687387#M37125</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T01:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687388#M37126</link>
      <description>&lt;P&gt;Why is date_start not 1/1 for pdct3?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 01:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687388#M37126</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-29T01:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687389#M37127</link>
      <description>&lt;P&gt;Because this crop plantation start in 11/Jan and ends in 20/Mar.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 01:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687389#M37127</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-29T01:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687392#M37128</link>
      <description>&lt;P&gt;So the crop plantation is not the first date_start? What's the rule for seeing that in the data?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 02:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687392#M37128</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-29T02:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687400#M37129</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349660"&gt;@carloshmcaldas&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one approach.&amp;nbsp; I modified my code to put in the year.&amp;nbsp; I chose 2020, but you should put in real years of course.&amp;nbsp; Then, below that, I added some SQL.&amp;nbsp; The SQL gives us the earliest date_start and the last date_end.&amp;nbsp; Is this what you need?&amp;nbsp; I show the results at the very bottom.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Crop_Data;
	INFILE	DATALINES4
			DSD	DLM='-'
			FIRSTOBS=2
			;

	FORMAT	state 		$3.
			city 		$3.
			crop 		$3.
			product 	$5.
			weeK		$2.
			Date_Start	DATE9.
			Date_End	DATE9.
			;
	
	INPUT	State		:	$3.
			City		:	$3.
			Crop		:	$3.
			Product		:	$5.
			Week		:	$2.
			Date_Start	:	ddmmyy10.
			Date_End	:	ddmmyy10.
			;

DATALINES4;
state - city - crop - product - week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1/2020    -    10/1/2020
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1/2020    -    20/1/2020
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1/2020    -    31/1/2020
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12/2020    -   10/12/2020
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12/2020    -   20/12/2020
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12/2020    -   31/12/2020
st1   - ct1  - cr1  -  pdct2  -   1  -    1/1/2020    -    10/1/2020
st1   - ct1  - cr1  -  pdct2  -   2  -    11/1/2020    -    20/1/2020
st1   - ct1  - cr1  -  pdct2  -  35  -   11/12/2020    -   20/12/2020
st1   - ct1  - cr1  -  pdct2  -  36  -   21/12/2020    -   31/12/2020
st1   - ct1  - cr1  -  pdct3  -   5  -   11/1/2020    -    20/2/2020
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1/2020    -    28/2/2020
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1/2020    -    10/3/2020
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1/2020    -    20/3/2020
;;;;
RUN;

PROC	SQL;
	CREATE	TABLE	CROP_DATA_RANGES	AS
		SELECT	State
				,City
				,Crop
				,Product
				,MIN(Date_Start)		AS	Date_Start	FORMAT	YYMMDDS10.
				,MAX(Date_End)			AS	Date_End	FORMAT	YYMMDDS10.
			FROM	Crop_Data
			GROUP	BY	State
				,City
				,Crop
				,Product
			;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;DIV id="tinyMceEditorjimbarbour_6" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601346817682.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49915i5F792A6E927F2131/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1601346817682.png" alt="jimbarbour_0-1601346817682.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 02:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687400#M37129</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T02:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687618#M37130</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349660"&gt;@carloshmcaldas&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Was that last bit of code helpful?&amp;nbsp; I think it is what you need (after you add the real years).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687618#M37130</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T18:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687659#M37132</link>
      <description>&lt;P&gt;The crop plantation definition order is the week sequence.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687659#M37132</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-29T21:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687664#M37133</link>
      <description>&lt;P&gt;no, because we can't use a year value, only date and month. the order is defined by week sequence. If the sequence&amp;nbsp; start at week 1 but it's interrupted, the correct sequence starts in the next order.&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the week sequence is solved, whe use the date_start from the first row and date_end from the last row.&lt;/P&gt;&lt;P&gt;Product 1 input:&lt;/P&gt;&lt;PRE&gt;state - city - crop - product - week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1    -    31/1    
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12    -   10/12    
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12    -   31/12    &lt;/PRE&gt;&lt;P&gt;Product 1 correct week sequence:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;state - city - crop - product - week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12    -   10/12    
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12    -   20/12    
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12    -   31/12    
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1    -    10/1    
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1    -    20/1    
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1    -    31/1    &lt;/PRE&gt;&lt;P&gt;Product 1 correct output:&lt;/P&gt;&lt;PRE&gt;state - city - crop - product - date_start -  date_end 
st1   - ct1  - cr1  -  pdct1  -    1/12    -    31/1    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687664#M37133</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-29T21:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687666#M37134</link>
      <description>&lt;P&gt;Great! But please explain the sequence for Product 3. That one eludes me.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687666#M37134</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-29T21:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687668#M37135</link>
      <description>&lt;P&gt;If the full date is present in the database, I would highly recommend that the full date, including year, be pulled from the database.&amp;nbsp; The date can be &lt;EM&gt;formatted&lt;/EM&gt; any way you like, but the date should be&amp;nbsp;&lt;EM&gt;stored&lt;/EM&gt; as a full numeric SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me see what I can do, but I strongly encourage using the full date from the database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687668#M37135</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T22:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687669#M37136</link>
      <description>&lt;P&gt;As pdct 3 only&amp;nbsp; has one week sequence, as week 5, 6, 7 and 8, whe use date_start from first row and date_end from last row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;st1   - ct1  - cr1  -  pdct3  -   5  -    11/1    -    20/2    
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1    -    30/2    
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1    -    10/3    
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1    -    20/3 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687669#M37136</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-09-29T22:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687676#M37137</link>
      <description>&lt;P&gt;OK, I think I understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have written the following code.&amp;nbsp; Please note the comments for each step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**	Read in the raw data	**;
DATA	Crop_Data;
	INFILE	DATALINES4
			DSD	DLM='-'
			FIRSTOBS=2
			;

	FORMAT	state 		$3.
			city 		$3.
			crop 		$3.
			product 	$5.
			Week		$2.
			Date_Start	$5.
			Date_End	$5.
			;
	
	INPUT	State		:	$3.
			City		:	$3.
			Crop		:	$3.
			Product		:	$5.
			Week		:	$2.
			Date_Start	:	$5.
			Date_End	:	$5.
			;

DATALINES4;
state - city - crop - product - Week - date_start - date_end
st1   - ct1  - cr1  -  pdct1  -   1  -     1/1    -    10/1
st1   - ct1  - cr1  -  pdct1  -   2  -    11/1    -    20/1
st1   - ct1  - cr1  -  pdct1  -   3  -    21/1    -    31/1
st1   - ct1  - cr1  -  pdct1  -  34  -    1/12    -   10/12
st1   - ct1  - cr1  -  pdct1  -  35  -   11/12    -   20/12
st1   - ct1  - cr1  -  pdct1  -  36  -   21/12    -   31/12
st1   - ct1  - cr1  -  pdct2  -   1  -    1/1    -    10/1
st1   - ct1  - cr1  -  pdct2  -   2  -    11/1    -    20/1
st1   - ct1  - cr1  -  pdct2  -  35  -   11/12    -   20/12
st1   - ct1  - cr1  -  pdct2  -  36  -   21/12    -   31/12
st1   - ct1  - cr1  -  pdct3  -   5  -   11/1    -    20/2
st1   - ct1  - cr1  -  pdct3  -   6  -    21/1    -    28/2
st1   - ct1  - cr1  -  pdct3  -   7  -     1/1    -    10/3
st1   - ct1  - cr1  -  pdct3  -   8  -    11/1    -    20/3
;;;;
RUN;

**	Sort by State, City, Crop, Product, and Week	**;
PROC	SORT	DATA=Crop_Data;
	BY	State City Crop Product Week;
RUN;

**	If there is a break in sequence, write records after the break to a second dataset	**;
DATA	Crop_Data1	Crop_Data2;
	FORMAT	state 			$3.
			city 			$3.
			crop 			$3.
			product 		$5.
			Week			$2.
			Date_Start		$5.
			Date_End		$5.
			;

	RETAIN	Prior_Week	0;
	RETAIN	Seq_Break	0;

	SET	Crop_Data;
		BY	State City Crop Product;

	IF	FIRST.Product			THEN	
		DO;
			Seq_Break		=	0;
			Prior_Week		=	Week;
			OUTPUT	Crop_Data1;
			DELETE;
		END;
	
	IF	Seq_Break				THEN
		DO;
			Prior_Week		=	Week;
			OUTPUT	Crop_Data2;
			DELETE;
		END;

	IF	Week				=	Prior_Week + 1	THEN
		DO;
			Prior_Week		=	Week;
			OUTPUT	Crop_Data1;
			DELETE;
		END;
	ELSE
		DO;
			Seq_Break		=	1;
			Prior_Week		=	Week;
			OUTPUT	Crop_Data2;
			DELETE;
		END;
RUN;

**	Recombine the data with records from after the sequence break *first*.	**;
DATA	Resequenced_Crop_Data;
	SET	Crop_Data2	Crop_Data1;
RUN;


**	Sort by State City Crop Product but NOT Week.	**;
PROC	SORT	DATA=Resequenced_Crop_Data	EQUALS
				OUT=Resequenced_Crop_Data_Sort;
	BY	State City Crop Product;
RUN;

**	Now that weeks are in the proper sequence, determine the date range.	**;
DATA	Crop_Data_Summarized(RENAME=(Save_Date_Start=Date_Start));
	FORMAT	state 			$3.
			city 			$3.
			crop 			$3.
			product 		$5.
			Week			$2.
			Save_Date_Start	$5.
			Date_Start		$5.
			Date_End		$5.
			;
	KEEP	State City Crop Product Save_Date_Start Date_End;
	SET	Resequenced_Crop_Data_Sort;
		BY	State City Crop Product;
	RETAIN	Save_Date_Start;
	IF	FIRST.Product		THEN
		Save_Date_Start	=	Date_Start;
	IF	LAST.Product	THEN
		OUTPUT;
	ELSE
		DELETE;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which produces:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601419976958.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49951iD6D02872D1FD5F33/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601419976958.png" alt="jimbarbour_0-1601419976958.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does that look?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/687676#M37137</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-29T22:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/688367#M37151</link>
      <description>&lt;P&gt;Works like a charm &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 21:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/688367#M37151</guid>
      <dc:creator>carloshmcaldas</dc:creator>
      <dc:date>2020-10-01T21:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Finding correct time range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/688369#M37152</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349660"&gt;@carloshmcaldas&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're welcome.&amp;nbsp; Sorry it took so many iterations to come up with a solution.&amp;nbsp; It took me a while before I really understood the situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps in whatever you are doing!&amp;nbsp; Good luck,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 21:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-correct-time-range/m-p/688369#M37152</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T21:06:51Z</dc:date>
    </item>
  </channel>
</rss>

