<?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: Creating custom fields to filter date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608880#M17773</link>
    <description>&lt;P&gt;Thank you very much for helping! The filter worked just fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table was programmed by others some time ago, but I'll totally consider revisiting it to adapt this field to SAS date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm kinda new to SAS language, and I don't really know the best practices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;</description>
    <pubDate>Mon, 02 Dec 2019 22:21:29 GMT</pubDate>
    <dc:creator>Renan_Crepaldi</dc:creator>
    <dc:date>2019-12-02T22:21:29Z</dc:date>
    <item>
      <title>Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608712#M17746</link>
      <description>&lt;P&gt;Hello, everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create custom fields to filter the last 12 months of a data set. The point is that the only column that contains a date variable is a numeric YYYYMM field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've succesfully created a first method, but it has a flaw. When it gets to January, my calculation will give a wrong result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	FORMAT STARTDATE FINALDATE BEST6.;
	STARTDATE = ((YEAR(TODAY())-1)*100)+MONTH(TODAY());
	FINALDATE = (YEAR(TODAY())*100)+MONTH(TODAY())-1;
	CALL SYMPUT ('STARTDATE',STARTDATE);
	CALL SYMPUT ('FINALDATE',FINALDATE);
RUN;

%PUT &amp;amp;STARTDATE.;
%PUT &amp;amp;FINALDATE.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to make this function work? I know that the INTX function would be more correct, but I don't know how to adapt it for a numeric date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 14:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608712#M17746</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2019-12-02T14:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608716#M17747</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267853"&gt;@Renan_Crepaldi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create custom fields to filter the last 12 months of a data set. The point is that the only column that contains a date variable is a numeric YYYYMM field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've succesfully created a first method, but it has a flaw. When it gets to January, my calculation will give a wrong result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	FORMAT STARTDATE FINALDATE BEST6.;
	STARTDATE = ((YEAR(TODAY())-1)*100)+MONTH(TODAY());
	FINALDATE = (YEAR(TODAY())*100)+MONTH(TODAY())-1;
	CALL SYMPUT ('STARTDATE',STARTDATE);
	CALL SYMPUT ('FINALDATE',FINALDATE);
RUN;

%PUT &amp;amp;STARTDATE.;
%PUT &amp;amp;FINALDATE.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a better way to make this function work? I know that the INTX function would be more correct, but I don't know how to adapt it for a numeric date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This creation of date fields such as 201901 are usually a poor choice, for the reason you have found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally, you want to use SAS date values, which are integers that indicate the number of days since January 1, 1960, and so adding one month to December 2018 takes you into January 2019. This is particularly easy using the INTNX function. Since these date numbers are not really useful when humans look at the date numbers, you want to format them to make them human-readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    startdate=intnx('year',today(),-1,'s');
    finaldate=intnx('day',today(),-1,'s');
    call symputx('startdate',startdate);
    call symputx('finaldate',finaldate);
run;

%put &amp;amp;startdate %sysfunc(putn(&amp;amp;startdate,yymm8.));
%put &amp;amp;finaldate %sysfunc(putn(&amp;amp;finaldate,yymm8.));&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;So macro variables should contain valid SAS date values, the number of days since Jan 1 1960, and they should only be formatted when humans need to look at them, such as output tables or if a human has to provide input to a macro/program.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 15:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608716#M17747</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-02T15:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608760#M17756</link>
      <description>&lt;P&gt;Hi, Paige. Thank you so much for replying!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This method works just fine. The results are exactly what I want, but the query that uses this dates doesn't understand this format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I mentioned, the field that I'll use as a filter is numeric, and it's using the date value resulted wrongly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I convert the result to a numeric YYYYMM?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 16:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608760#M17756</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2019-12-02T16:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608767#M17757</link>
      <description>&lt;P&gt;Show us a portion of the data you are using, and the query that doesn't work. Also, please confirm and state clearly whether this number that looks like 201812 is truly numeric and not character.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 16:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608767#M17757</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-02T16:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608775#M17759</link>
      <description>&lt;P&gt;Of course, Paige. Sorry for not having specified these elements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The field that I'm using as filter have these properties:&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="image.png" style="width: 483px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34382i0926AE60105ADDAB/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After running the code you sent, the results are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;35         %put &amp;amp;DTINICIAL %sysfunc(putn(&amp;amp;DTINICIAL,yymm8.));
21520  2018M12
36         %put &amp;amp;DTFINAL %sysfunc(putn(&amp;amp;DTFINAL,yymm8.));
21855  2019M11&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using them as filters will results on null values, since there aren't data between these "dates" (21520 and 21855).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need more information, please, tell me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 16:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608775#M17759</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2019-12-02T16:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608794#M17763</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Show us a portion of the data you are using&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 17:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608794#M17763</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-02T17:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608802#M17765</link>
      <description>&lt;P&gt;Sorry, Paige. The data that I'm working on is from my company, and I was afraid of sharing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I adapted it to English so you can understand (hopefully hahaha):&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="image.png" style="width: 698px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34384i8D7B73308A2F6111/image-dimensions/698x50?v=v2" width="698" height="50" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the patience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 18:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608802#M17765</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2019-12-02T18:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608807#M17768</link>
      <description>&lt;P&gt;If you are receiving the values of NUM_AND_MES in that format, then you will have to deal with them in that format. If you are creating them in that format, then I strongly suggest you change the program to have variable NUM_AND_MES as SAS data values (integers showing number of days since Jan 1, 1960) and then format them to be human-understandable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they arrive as 201501 then this will allow your SQL to work properly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;dtinicial&amp;lt;=input(put(num_and_mes,7.),yymmn6.)&amp;lt;=&amp;amp;dtfinal&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will probably be inefficient for very large data sets.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 18:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608807#M17768</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-02T18:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom fields to filter date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608880#M17773</link>
      <description>&lt;P&gt;Thank you very much for helping! The filter worked just fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table was programmed by others some time ago, but I'll totally consider revisiting it to adapt this field to SAS date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm kinda new to SAS language, and I don't really know the best practices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 22:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-custom-fields-to-filter-date/m-p/608880#M17773</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2019-12-02T22:21:29Z</dc:date>
    </item>
  </channel>
</rss>

