<?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: convert variable from best12 to date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793133#M254162</link>
    <description>Thank you very much!</description>
    <pubDate>Fri, 28 Jan 2022 14:17:22 GMT</pubDate>
    <dc:creator>lillymaginta1</dc:creator>
    <dc:date>2022-01-28T14:17:22Z</dc:date>
    <item>
      <title>convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792957#M254093</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    month_dt
cards;
001 2017101
001 2017205
003 2018205 
004 2018204 

;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the above variable month_dt in best12 format, how can I change the format to mmddyy?&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 18:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792957#M254093</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2022-01-27T18:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792967#M254097</link>
      <description>&lt;P&gt;Assuming the 5th digit is not really useful (quarter?):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
set have;
monthDate = mdy(mod(month_dt,100),1,floor(month_dt/1000));
format monthDate mmddyy.;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1643310771019.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67938i7D11640D9F1145FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1643310771019.png" alt="PGStats_0-1643310771019.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792967#M254097</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-01-27T19:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792968#M254098</link>
      <description>&lt;P&gt;So, month_dt is not a SAS date variable. It may look like it to humans, but to SAS it is just an integer. And so you have to use INPUT with the proper format to turn month_dt into a valid SAS date. But first you need to use PUT to turn it into a character string (because INPUT doesn't work on integers)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    month_dt;
cards;
001 20170101
001 20170205
003 20180205 
004 20180204 

;
data want;
    set have;
    want_dt=input(put(month_dt,8.),yymmdd8.);
    format want_dt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69937"&gt;@lillymaginta1&lt;/a&gt;&amp;nbsp;Please proofread, as you are using dates 2018204, which as a 7digit integer is actually meaningless and could be interpreted many ways. I have changed your 7 digit dates to 8 digit dates, otherwise this won't work. Please also specify which column is month and which is day, as your example doesn't make this clear, and I had to guess.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792968#M254098</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-27T19:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792969#M254099</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69937"&gt;@lillymaginta1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    month_dt
cards;
001 2017101
001 2017205
003 2018205 
004 2018204 

;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the above variable month_dt in best12 format, how can I change the format to mmddyy?&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First thing is may need to explicitly state what date those values represent. Is 2017205&amp;nbsp; 20 May 2017 or 5 Feb 2017 or 24 Jul 2017 (julian date)? .&lt;/P&gt;
&lt;P&gt;Typically any of the year month day date appearance uses 2 digits for both the month and year to provide consistency. If your Month is only 1 digit then you need to state that and be prepared to deal with extra conditional coding because of poor structure of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the 2017205 is a Julian date then use the DATEJUL function to convert to a typical SAS date and apply desired format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;month_dt = datejul(month_dt);
format month_dt mmddyy10.;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792969#M254099</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-27T19:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792977#M254100</link>
      <description>2018204 -&amp;gt; what is the interpretation of that value to a date?&lt;BR /&gt;&lt;BR /&gt;2018-2-04?&lt;BR /&gt;2018-20(day) -4Month(?)&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/792977#M254100</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-27T19:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793122#M254156</link>
      <description>&lt;P&gt;Thank you everyone for the suggestions and apologize for the lack of clarity. The date is entered as month year but for some reason there is extra digit to the right. The date is entered in the data as "2017101" and the type was set to Best12. None of the code above worked. Other dat entries include&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2017410&lt;/P&gt;
&lt;P&gt;2017309&lt;/P&gt;
&lt;P&gt;2017412&lt;/P&gt;
&lt;P&gt;2018205&lt;/P&gt;
&lt;P&gt;I am not sure which digit should be removed before running any of the codes suggested above.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 13:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793122#M254156</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2022-01-28T13:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793124#M254157</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The date is entered as month year&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm sorry but this clears nothing up. Saying month year indicates month is first, but your dates are 2017410, so the month is 20 and the year is 1741? Furthermore I specifically asked "Please also specify which column is month and which is day", not which is month and which is year.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please explain this better. And we cannot work with 7 digit dates.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 13:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793124#M254157</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-28T13:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793127#M254159</link>
      <description>&lt;P&gt;&lt;SPAN&gt;for the following number '2017410', 2017 would be the year and the month is the last two digits: 10. The number 4 is the quarter&amp;nbsp;of the year so it needs to be dropped.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 14:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793127#M254159</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2022-01-28T14:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793129#M254160</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    year=floor(month_dt/1000);
    month=mod(month_dt,100);
    date=mdy(month,1,year);
    format date date9.;
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The math above (using FLOOR and MOD) takes parts of your MONTH_DT integer and determines year and month. MDY turns year and month into an actual SAS date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 14:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793129#M254160</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-28T14:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793133#M254162</link>
      <description>Thank you very much!</description>
      <pubDate>Fri, 28 Jan 2022 14:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793133#M254162</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2022-01-28T14:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable from best12 to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793154#M254172</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69937"&gt;@lillymaginta1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;for the following number '2017410', 2017 would be the year and the month is the last two digits: 10. The number 4 is the quarter&amp;nbsp;of the year so it needs to be dropped.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Strongly suggest whipping with spaghetti noodles for whoever came up with that "brilliant" layout for displaying dates.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 15:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-from-best12-to-date/m-p/793154#M254172</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-28T15:34:39Z</dc:date>
    </item>
  </channel>
</rss>

