<?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: Delete rows/observations based on date value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761464#M240967</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;

SET HAVE;

IF VAR1 = 0 THEN DELETE;

IF put(DATE, YYQ6.) = "2013Q4" THEN DELETE;

if year(date) = 2013 and qtr(date) = 4 then delete;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FYI - do not use this style of programming. It's harder to debug and find any issues in your programming, instead give your output data set a unique name as above otherwise you cannot trace your work between steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
SET HAVE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393094"&gt;@pbhatt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I have at the moment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA = HAVE;&lt;BR /&gt;BY DATE ;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;IF VAR1 = 0 THEN DELETE;&lt;BR /&gt;IF DATE = 2013Q4 THEN DELETE;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Aug 2021 16:35:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-08-13T16:35:16Z</dc:date>
    <item>
      <title>Delete rows/observations based on date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761459#M240965</link>
      <description>&lt;P&gt;I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I have at the moment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SORT DATA = HAVE;&lt;BR /&gt;BY DATE ;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;IF VAR1 = 0 THEN DELETE;&lt;BR /&gt;IF DATE = 2013Q4 THEN DELETE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 16:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761459#M240965</guid>
      <dc:creator>pbhatt</dc:creator>
      <dc:date>2021-08-13T16:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows/observations based on date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761464#M240967</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;

SET HAVE;

IF VAR1 = 0 THEN DELETE;

IF put(DATE, YYQ6.) = "2013Q4" THEN DELETE;

if year(date) = 2013 and qtr(date) = 4 then delete;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FYI - do not use this style of programming. It's harder to debug and find any issues in your programming, instead give your output data set a unique name as above otherwise you cannot trace your work between steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
SET HAVE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393094"&gt;@pbhatt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I have at the moment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA = HAVE;&lt;BR /&gt;BY DATE ;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;IF VAR1 = 0 THEN DELETE;&lt;BR /&gt;IF DATE = 2013Q4 THEN DELETE;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 16:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761464#M240967</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-13T16:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows/observations based on date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761466#M240969</link>
      <description>Thanks so much! It worked! Also, I tried another method as well which also worked:&lt;BR /&gt;DATA WORK.TEST1;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;IF VAR1 = 0 THEN DELETE;&lt;BR /&gt;IF DISCHARGE &amp;lt; '01OCT2013'D THEN DELETE;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;Also, thanks again Reeza for the tips. I will make sure to use better syntax so I can trace my steps/mistakes and troubleshoot.</description>
      <pubDate>Fri, 13 Aug 2021 16:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761466#M240969</guid>
      <dc:creator>pbhatt</dc:creator>
      <dc:date>2021-08-13T16:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows/observations based on date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761470#M240973</link>
      <description>&lt;P&gt;Your code technically works but it deletes anything prior to Q4, not just in the third quarter which is what your original code was trying to do. &lt;BR /&gt;Only you know which one is right, as this isn't a technical question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simplify it slightly if desired as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.TEST1;
SET HAVE;
IF VAR1 = 0 or  DISCHARGE &amp;lt; '01OCT2013'D THEN DELETE;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 16:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-observations-based-on-date-value/m-p/761470#M240973</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-13T16:56:27Z</dc:date>
    </item>
  </channel>
</rss>

