<?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 Understanding of date value with macro variables and any date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613195#M179058</link>
    <description>&lt;P&gt;I've the data as follows. For the below macro variable (Reportingdate), if I change the value to 2017-03,&amp;nbsp; I'm getting the different value in IR. Could you help me understand why the Format anydtdte7. producing the different values (02FEB2017 and 01MAR2017 for the first two observations)&amp;nbsp;in the Output, for the similar Input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_new;
input PROFITABILITY_FLG $ PREMIUM_DUE_MONTH $ COVERAGE_PERIOD_START_MONTH $;
datalines;
L 2002-06 2001-06
L  2003-06 2003-06
P 2004-06 2002-06
;
run;

%let REPORTINGDATE=20170331;
proc sql;
create table output as select *,CASE   
WHEN PROFITABILITY_FLG= "" then . 
WHEN PROFITABILITY_FLG= "L" then input("&amp;amp;REPORTINGDATE.",anydtdte7.) 
WHEN PROFITABILITY_FLG ne "L" then min(input(PREMIUM_DUE_MONTH,anydtdte7.),input(COVERAGE_PERIOD_START_MONTH,anydtdte7.) )  
END as IR format=date9. from test_new;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Dec 2019 07:53:34 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-12-20T07:53:34Z</dc:date>
    <item>
      <title>Understanding of date value with macro variables and any date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613195#M179058</link>
      <description>&lt;P&gt;I've the data as follows. For the below macro variable (Reportingdate), if I change the value to 2017-03,&amp;nbsp; I'm getting the different value in IR. Could you help me understand why the Format anydtdte7. producing the different values (02FEB2017 and 01MAR2017 for the first two observations)&amp;nbsp;in the Output, for the similar Input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_new;
input PROFITABILITY_FLG $ PREMIUM_DUE_MONTH $ COVERAGE_PERIOD_START_MONTH $;
datalines;
L 2002-06 2001-06
L  2003-06 2003-06
P 2004-06 2002-06
;
run;

%let REPORTINGDATE=20170331;
proc sql;
create table output as select *,CASE   
WHEN PROFITABILITY_FLG= "" then . 
WHEN PROFITABILITY_FLG= "L" then input("&amp;amp;REPORTINGDATE.",anydtdte7.) 
WHEN PROFITABILITY_FLG ne "L" then min(input(PREMIUM_DUE_MONTH,anydtdte7.),input(COVERAGE_PERIOD_START_MONTH,anydtdte7.) )  
END as IR format=date9. from test_new;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Dec 2019 07:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613195#M179058</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-12-20T07:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of date value with macro variables and any date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613205#M179064</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason is the inappropriate length 7 of informat &lt;FONT face="courier new,courier"&gt;anydtdte&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;.&lt;/FONT&gt; for the value "20170331", which has length &lt;STRONG&gt;8&lt;/STRONG&gt;, i.e., the informat converts "2017033" into a SAS date value. Thanks to the notorious flexibility of the ANYDT... informats this conversion is successful:&amp;nbsp;"2017033" can be interpreted as the &lt;EM&gt;Julian&lt;/EM&gt; date value "33rd day of the year 2017", which is 02FEB2017. (Search for "JULIAN" in the &lt;A href="https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=n04jh1fkv5c8zan14fhqcby7jsu4.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;documentation of the ANYDTDTE informat&lt;/A&gt;.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, for "20170331" use &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;yymmn6.&lt;/FONT&gt;&lt;/STRONG&gt; if you want to obtain 01MAR2017 (and ignore the "31") or &lt;FONT face="courier new,courier"&gt;anydtdte&lt;STRONG&gt;8&lt;/STRONG&gt;.&lt;/FONT&gt;&amp;nbsp;(or &lt;FONT face="courier new,courier"&gt;yymmdd8.&lt;/FONT&gt;) for the result 31MAR2017.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 09:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613205#M179064</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-20T09:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of date value with macro variables and any date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613206#M179065</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using the anydtdte. format solves the issue. Day is set to the first of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_new;
	input PROFITABILITY_FLG $ PREMIUM_DUE_MONTH $ COVERAGE_PERIOD_START_MONTH $;
	datalines;
L 2002-06 2001-06
L  2003-06 2003-06
P 2004-06 2002-06
P 2001-12 2005-06
;
run;

%let REPORTINGDATE=20170331;

proc sql;
	create table output as
	select *,
		   CASE WHEN PROFITABILITY_FLG="" then . 
		   		WHEN PROFITABILITY_FLG="L" then input("&amp;amp;REPORTINGDATE", anydtdte.)
		   		WHEN PROFITABILITY_FLG ne "L" then min(input(PREMIUM_DUE_MONTH, anydtdte.), input(COVERAGE_PERIOD_START_MONTH, anydtdte.) )
		   		ELSE .
		   END as IR format=date9.
	from test_new;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 09:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-date-value-with-macro-variables-and-any-date/m-p/613206#M179065</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-20T09:45:09Z</dc:date>
    </item>
  </channel>
</rss>

