<?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: selecting data in the first 30 days since first date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256831#M49260</link>
    <description>You cannot use first. or last. variables within a where statement since where does the filtering in the input buffers. And that's prior to when the data hits the PDV (and that's where the first. variables are created).&lt;BR /&gt;&lt;BR /&gt;If you wish to accomplish this in a single step look into SQL:&lt;BR /&gt;having order_date &amp;lt; min (order_date) +30</description>
    <pubDate>Tue, 15 Mar 2016 16:22:17 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-03-15T16:22:17Z</dc:date>
    <item>
      <title>selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256824#M49254</link>
      <description>&lt;P&gt;I have 3 variables, ID, order_date, and order_amount for a year, and I want to get the first 30days data starting from the first order date for each ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=year_data;
by ID order_date;
run;

data first_month;
set year_data;
by ID order_date; &lt;BR /&gt;where day(order_date) - day(first.order_date) &amp;lt;=30; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;this does not work. There is a syntax error at day(first.order_date). What is wrong there?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 16:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256824#M49254</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-03-15T16:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256831#M49260</link>
      <description>You cannot use first. or last. variables within a where statement since where does the filtering in the input buffers. And that's prior to when the data hits the PDV (and that's where the first. variables are created).&lt;BR /&gt;&lt;BR /&gt;If you wish to accomplish this in a single step look into SQL:&lt;BR /&gt;having order_date &amp;lt; min (order_date) +30</description>
      <pubDate>Tue, 15 Mar 2016 16:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256831#M49260</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-15T16:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256835#M49263</link>
      <description>&lt;P&gt;that works! thank you for teaching me!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 16:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256835#M49263</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-03-15T16:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256839#M49265</link>
      <description>&lt;P&gt;Well, you could do something like:&lt;/P&gt;
&lt;PRE&gt;data first_month;
  set year_data;
  by id;
  retain first_date;
  if first.if then first_date=order_date;
  if first_date &amp;lt;= order_date &amp;lt;= intnx('month',first_date,1,'same') then output;
run;&lt;/PRE&gt;
&lt;P&gt;Note I am assuming that date is a date variable not a datetime. &amp;nbsp;This will output only rows between first_date and first_date+1 month.t&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 16:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/256839#M49265</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-15T16:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257059#M49313</link>
      <description>Thank you, RW9. This requires both ID and order_date need to be sorted, right? But there is only id in the by statement.</description>
      <pubDate>Wed, 16 Mar 2016 16:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257059#M49313</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-03-16T16:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257063#M49314</link>
      <description>&lt;P&gt;Yes, it reuiqres the data to be sorted, as per the proc sort in your first post. &amp;nbsp;The date does not need to be in the by line however, what I am doing is retaining the first observation for each id across the id, then using that to compare to the current observations date.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 16:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257063#M49314</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-16T16:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: selecting data in the first 30 days since first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257120#M49336</link>
      <description>&lt;P&gt;Thank you, RW9.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 20:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-data-in-the-first-30-days-since-first-date/m-p/257120#M49336</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-03-16T20:02:53Z</dc:date>
    </item>
  </channel>
</rss>

