<?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: Rearrange dataset based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669613#M200904</link>
    <description>Correct compare it with first record and follow on with others</description>
    <pubDate>Wed, 15 Jul 2020 17:39:46 GMT</pubDate>
    <dc:creator>Shuail_Ibrahim</dc:creator>
    <dc:date>2020-07-15T17:39:46Z</dc:date>
    <item>
      <title>Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669509#M200852</link>
      <description>&lt;P&gt;I have a dataset which has index and date&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;I need to perform logic in which I need to compare the first value with next date if the date range is lesser than 31 remove the second, again compare the first with third if it's greater than 31 keep the first and third and compare the third with fourth if less remove or if greater add keep on like this. please help me out with a SAS or SQL query&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;dataset&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dataset 
index&amp;nbsp; &amp;nbsp; &amp;nbsp;DATE
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-01-01
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-01-15
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-01-30
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-02-02
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-02-20
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-03-05
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-03-25
2&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-04-30


required dataset 
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-01-01
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-02-02
1&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-03-05
2&amp;nbsp; &amp;nbsp; &amp;nbsp;2020-04-30&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 15:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669509#M200852</guid>
      <dc:creator>Shuail_Ibrahim</dc:creator>
      <dc:date>2020-07-15T15:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669524#M200862</link>
      <description>Do you just want the first record for every month or is it more complicated than that?</description>
      <pubDate>Wed, 15 Jul 2020 15:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669524#M200862</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-15T15:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669547#M200867</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*make fake data;
data have;
input index date : yymmdd10.;
format date date9.;
cards;
1     2020-01-01
1     2020-01-15
1     2020-01-30
1     2020-02-02
1     2020-02-20
1     2020-03-05
1     2020-03-25
2     2020-04-30
;;;;
run;

proc sort data=have;
by index date;
run;

*keep the first record of each person/month;
data want;
set have;
by index date groupformat;
format date yymm6.;
if first.date;
run;

*format the date back to yymmdd format for display;
proc datasets lib=work nodetails nolist;
modify want;
format date yymmddd10.;
run;

*display results;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so, use the GROUPFORMAT option and format your date as a year month format and SAS will pick the first record for every month.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 15:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669547#M200867</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-15T15:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669565#M200878</link>
      <description>if its min date range from each month this query works, but I need to compare between each date a span of 31...&lt;BR /&gt;&lt;BR /&gt;select index, MIN(date) from indextbl&lt;BR /&gt;group by index, LEFT(date,7)&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jul 2020 16:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669565#M200878</guid>
      <dc:creator>Shuail_Ibrahim</dc:creator>
      <dc:date>2020-07-15T16:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669571#M200881</link>
      <description>Span of 31 days gap fails in the above</description>
      <pubDate>Wed, 15 Jul 2020 16:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669571#M200881</guid>
      <dc:creator>Shuail_Ibrahim</dc:creator>
      <dc:date>2020-07-15T16:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669579#M200886</link>
      <description>So the rule is all dates need to be 31 days or more apart? Your logic isn't specified clearly:&lt;BR /&gt; "again compare the first with third if it's greater than 31 keep the first and third and compare the third with fourth if less remove or if greater add keep on like this."&lt;BR /&gt;&lt;BR /&gt;It seems like you're comparing to both the first and the prior records?</description>
      <pubDate>Wed, 15 Jul 2020 16:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669579#M200886</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-15T16:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rearrange dataset based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669613#M200904</link>
      <description>Correct compare it with first record and follow on with others</description>
      <pubDate>Wed, 15 Jul 2020 17:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearrange-dataset-based-on-condition/m-p/669613#M200904</guid>
      <dc:creator>Shuail_Ibrahim</dc:creator>
      <dc:date>2020-07-15T17:39:46Z</dc:date>
    </item>
  </channel>
</rss>

