<?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: Automatic selection of periods/date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/800575#M314978</link>
    <description>Thank you!</description>
    <pubDate>Mon, 07 Mar 2022 07:11:52 GMT</pubDate>
    <dc:creator>Chris_LK_87</dc:creator>
    <dc:date>2022-03-07T07:11:52Z</dc:date>
    <item>
      <title>Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799331#M314304</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset that have three variables: period (datevar.), sales and depart. The time series starts in 2021-01-01 and grows every month when a new month’s salesfigures is added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For now I am using a macro that I have to update every month; eg. current date minus two months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a macro, with TODAY Function or something else, so I can automatically select periods that is the current date minus two months without needing to updated the macro every month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;input period :yymmdd10. sales depart$;&lt;/P&gt;
&lt;P&gt;format period yymmddd10.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2021-01-01 200 Sales&lt;/P&gt;
&lt;P&gt;2021-02-02 150 Sales&lt;/P&gt;
&lt;P&gt;2021-03-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-04-01 220 Sales&lt;/P&gt;
&lt;P&gt;2021-05-01 250 Sales&lt;/P&gt;
&lt;P&gt;2021-06-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-07-01 400 Sales&lt;/P&gt;
&lt;P&gt;2021-08-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-09-01 900 Sales&lt;/P&gt;
&lt;P&gt;2021-10-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-11-01 850 Sales&lt;/P&gt;
&lt;P&gt;2021-12-01 750 Sales&lt;/P&gt;
&lt;P&gt;2022-01-01 650 Sales&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let time=('01jan2021'd&amp;lt;=period&amp;lt;='01jan2022'd);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data out;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if &amp;amp;time.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799331#M314304</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-01T15:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799333#M314305</link>
      <description>&lt;P&gt;Your example is not selecting "the current date minus two months" but apparently a previous YEAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two months might be:&lt;/P&gt;
&lt;PRE&gt; 
data out;
set have;
if intck('month',period,today() ) le 2;
run;&lt;/PRE&gt;
&lt;P&gt;You ask this question in MAR 2022 and only provide one value within 2 months for example data so there is only one record.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799333#M314305</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-01T15:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799334#M314306</link>
      <description>&lt;P&gt;SAS should be able to handle this without creating a macro.&amp;nbsp; You haven't described the end of the time period, so I'll assume you want 12 months in total:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   if intnx('month', today(), -2) &amp;lt;= period  &amp;lt; intnx('month', today(), 9);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799334#M314306</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-01T15:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799513#M314389</link>
      <description>&lt;P&gt;It could be longer, 12 months is onlys an example.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 07:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799513#M314389</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-02T07:12:53Z</dc:date>
    </item>
    <item>
      <title>Selection of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799525#M314400</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I asked a question earlier about this issue. I will try to rephrase my question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset that have three variables: period (datevar.), sales and depart. The time series starts in 2021-01-01 and grows every month when a new month’s sales figures is added. The data for the latest months (in this example 2022-02-01 and 2022-03-01) is not reliable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For now, I am using a macro that I must update every month. With the macro I select the starting date and the end date (current date minus two months.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a macro, with TODAY Function or something else, so I can automatically select starting date (2021-01-01) and end date (current date minus two months: 2021-01-01). I would like to achieve this without needing to update the macro every month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;input period :yymmdd10. sales depart$;&lt;/P&gt;
&lt;P&gt;format period yymmddd10.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2021-01-01 200 Sales&lt;/P&gt;
&lt;P&gt;2021-02-02 150 Sales&lt;/P&gt;
&lt;P&gt;2021-03-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-04-01 220 Sales&lt;/P&gt;
&lt;P&gt;2021-05-01 250 Sales&lt;/P&gt;
&lt;P&gt;2021-06-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-07-01 400 Sales&lt;/P&gt;
&lt;P&gt;2021-08-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-09-01 900 Sales&lt;/P&gt;
&lt;P&gt;2021-10-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-11-01 850 Sales&lt;/P&gt;
&lt;P&gt;2021-12-01 750 Sales&lt;/P&gt;
&lt;P&gt;2022-01-01 650 Sales&lt;/P&gt;
&lt;P&gt;2022-02-01 100 Sales&lt;/P&gt;
&lt;P&gt;2022-03-01 25&amp;nbsp; &amp;nbsp;Sales&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let time=('01jan2021'd&amp;lt;=period&amp;lt;='01jan2022'd);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data out;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if &amp;amp;time.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;input period :yymmdd10. sales depart$;&lt;/P&gt;
&lt;P&gt;format period yymmddd10.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2021-01-01 200 Sales&lt;/P&gt;
&lt;P&gt;2021-02-02 150 Sales&lt;/P&gt;
&lt;P&gt;2021-03-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-04-01 220 Sales&lt;/P&gt;
&lt;P&gt;2021-05-01 250 Sales&lt;/P&gt;
&lt;P&gt;2021-06-01 320 Sales&lt;/P&gt;
&lt;P&gt;2021-07-01 400 Sales&lt;/P&gt;
&lt;P&gt;2021-08-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-09-01 900 Sales&lt;/P&gt;
&lt;P&gt;2021-10-01 550 Sales&lt;/P&gt;
&lt;P&gt;2021-11-01 850 Sales&lt;/P&gt;
&lt;P&gt;2021-12-01 750 Sales&lt;/P&gt;
&lt;P&gt;2022-01-01 650 Sales&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 08:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799525#M314400</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-02T08:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799528#M314399</link>
      <description>&lt;P&gt;This creates a macro variable indicating the beginning of the next-to-last month:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cutoff = %sysfunc(intnx(month,%sysfunc(today()),-2,b));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This can easily be used in comparisons with SAS date values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date ge &amp;amp;cutoff.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 08:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799528#M314399</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-02T08:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Selection of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799530#M314401</link>
      <description>&lt;P&gt;I moved your second question back in here, as it deals with the same basic issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you want to automatically define a time span, starting at the beginning of two months and one year before now, and ending at the beginning of two months before now?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create the start and end points:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start = %sysfunc(intnx(month,%sysfunc(today()),-14,b));
%let end = %sysfunc(intnx(month,%sysfunc(today()),-2,b));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use them to subset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
where &amp;amp;start. le period le &amp;amp;end.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 09:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/799530#M314401</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-02T09:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic selection of periods/date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/800575#M314978</link>
      <description>Thank you!</description>
      <pubDate>Mon, 07 Mar 2022 07:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/800575#M314978</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-07T07:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selection of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/800576#M314979</link>
      <description>Thank you!</description>
      <pubDate>Mon, 07 Mar 2022 07:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-selection-of-periods-date/m-p/800576#M314979</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-07T07:12:12Z</dc:date>
    </item>
  </channel>
</rss>

