<?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: Date variable calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425713#M104868</link>
    <description>&lt;P&gt;For hardcoding a date literal in code, SAS has exactly one format, and that is the date9. in quotes with a trailing letter d. Period.&lt;/P&gt;
&lt;P&gt;201711 is not a date at all, as the day is missing. So you need to make up a day (first of month, usually) to get a complete date, and then you can apply a display format that only displays year and month (as already suggested).&lt;/P&gt;
&lt;P&gt;And I see no value in using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input('201711',yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'01nov2017'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first option only obfuscates the fact that SAS will create the first of November anyway, as can be seen in this log:&lt;/P&gt;
&lt;PRE&gt;24         data _null_;
25         x1 = input('201711',yymmn6.);
26         put x1= date9.;
27         run;

x1=01NOV2017
&lt;/PRE&gt;
&lt;P&gt;So in order to keep your code maintainable, use the classic SAS date notation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input function should only be used when you have string data (not literals!) that only consists of year and month. And even then I prefer&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input(trim(instr)!!'01',yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for clarity.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2018 10:10:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-01-08T10:10:05Z</dc:date>
    <item>
      <title>Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425702#M104861</link>
      <description>&lt;P&gt;I'm trying to create the variable as Reporting_dt by hardc oding the date value 201711 as given below. But I'm receiving the error as follows as mentioned in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
  select *,'201711'd as Reporting_dt 
  from sashelp.class
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;24         proc sql;
25         create table new as
26           select *,'201711'd as Reporting_dt
ERROR: Invalid date/time/datetime constant '201711'd.
27           from sashelp.class
28         ;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
29         quit;
NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once I create the Reporting_dt variable, I've to use year(&lt;SPAN&gt;Reporting_dt) to create another variable for some calculation. Appreciate if someone of you help me to get past this error.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 08:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425702#M104861</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-01-08T08:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425703#M104862</link>
      <description>&lt;P&gt;I like to use the date9 format when using date constants like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
  select *
		,'01nov2017'd as Reporting_dt format=date9.
  from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 08:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425703#M104862</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-08T08:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425704#M104863</link>
      <description>I need the Reporting_dt variable to populate the value as 201711&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Jan 2018 08:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425704#M104863</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-01-08T08:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425705#M104864</link>
      <description>&lt;P&gt;Then use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format=yymmn6.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 08:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425705#M104864</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-08T08:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425706#M104865</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;points out the 'd syntax requires a string in the form of DDMONYY&amp;lt;YY&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the string you want to pass in you could use&lt;/P&gt;
&lt;PRE&gt;input('201711',yymmn6.) as Reporting_dt format=date9.&lt;/PRE&gt;
&lt;P&gt;And then apply a format which prints the SAS date value the way you want it, i.e. format=yymmn6.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 08:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425706#M104865</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-01-08T08:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425713#M104868</link>
      <description>&lt;P&gt;For hardcoding a date literal in code, SAS has exactly one format, and that is the date9. in quotes with a trailing letter d. Period.&lt;/P&gt;
&lt;P&gt;201711 is not a date at all, as the day is missing. So you need to make up a day (first of month, usually) to get a complete date, and then you can apply a display format that only displays year and month (as already suggested).&lt;/P&gt;
&lt;P&gt;And I see no value in using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input('201711',yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'01nov2017'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first option only obfuscates the fact that SAS will create the first of November anyway, as can be seen in this log:&lt;/P&gt;
&lt;PRE&gt;24         data _null_;
25         x1 = input('201711',yymmn6.);
26         put x1= date9.;
27         run;

x1=01NOV2017
&lt;/PRE&gt;
&lt;P&gt;So in order to keep your code maintainable, use the classic SAS date notation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input function should only be used when you have string data (not literals!) that only consists of year and month. And even then I prefer&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input(trim(instr)!!'01',yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for clarity.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 10:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variable-calculation/m-p/425713#M104868</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-08T10:10:05Z</dc:date>
    </item>
  </channel>
</rss>

