<?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: SAS Char date YYYY:M into Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395784#M95511</link>
    <description>&lt;P&gt;What do you want the day to represent, 1, 15, last day of the month?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the MDY() function is probably the easiest here. I broke out how to create the parts if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
 char_date = "2017-8";output;
 char_date = "2017-10";output;
 run;

 data want;
 set have;

 year_char = scan(char_date, 1, "-");
 year_num = input(year_char, 8.);
 *same for month, or nest it all in one;
 date_sas = mdy(input(scan(char_date, 2, "-"), 8.) , 1, input(scan(char_date, 1, "-"), 8.));

 format date_sas yymon7.;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Sep 2017 22:12:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-09-13T22:12:58Z</dc:date>
    <item>
      <title>SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395782#M95509</link>
      <description>&lt;P&gt;Hello, I have a variable Date in Char format. I would like to convert that into Date format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;----------&lt;/P&gt;&lt;P&gt;2017-8&lt;/P&gt;&lt;P&gt;2016-7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395782#M95509</guid>
      <dc:creator>K1235</dc:creator>
      <dc:date>2017-09-13T22:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395784#M95511</link>
      <description>&lt;P&gt;What do you want the day to represent, 1, 15, last day of the month?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the MDY() function is probably the easiest here. I broke out how to create the parts if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
 char_date = "2017-8";output;
 char_date = "2017-10";output;
 run;

 data want;
 set have;

 year_char = scan(char_date, 1, "-");
 year_num = input(year_char, 8.);
 *same for month, or nest it all in one;
 date_sas = mdy(input(scan(char_date, 2, "-"), 8.) , 1, input(scan(char_date, 1, "-"), 8.));

 format date_sas yymon7.;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395784#M95511</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T22:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395787#M95514</link>
      <description>&lt;P&gt;Sorry, I want to just output yyyy-mm no day. Also, your second char_date outputed 2017JAN not 2017OCT&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395787#M95514</guid>
      <dc:creator>K1235</dc:creator>
      <dc:date>2017-09-13T22:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395790#M95516</link>
      <description>&lt;P&gt;There is no such thing. &amp;nbsp;In SAS, dates always refer to a specific day. &amp;nbsp;Always. &amp;nbsp;You can change the value of your character variable if you would like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length date $ 7;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if length(date)=6 then date = cats(substr(date,1,5), '0', substr(date, 6,1));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That creates DATE as a character string, with slightly different values than what it had before. &amp;nbsp;But if you want what SAS considers to be a date, this is not it.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395790#M95516</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-13T22:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395791#M95517</link>
      <description>&lt;P&gt;ah..that's because there's a problem with the test data - note the answer though. I didn't assign a variable length so SAS defaults to the first it found, so it read it as 2017-1, not 2017-10.&lt;/P&gt;
&lt;P&gt;A SAS date has to have a day component, though you can show only the month year as shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, find the format you want and change the format statement to what you want to see.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The formats are here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395791#M95517</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T22:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Char date YYYY:M into Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395792#M95518</link>
      <description>&lt;P&gt;SAS will require a day of month as part of the value to be treated as a "date" variable for any of the functions.&lt;/P&gt;
&lt;P&gt;Best might be to read with the anydtdte. format.&lt;/P&gt;
&lt;PRE&gt;data  example;
   input x $;
   y = input(x,anydtdte.) ;
   format y yymmd7.;
   yy=year(y);
   mm=month(y);
   dd=day(y);
datalines;
2017-8
2016-7
2016-10
;
run;&lt;/PRE&gt;
&lt;P&gt;Note that the format I assigned will mimic the input values only the month will always have two digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that other SAS defaults can apply when reading quarters into dates where the month and day are the first of the calendar quarter&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Char-date-YYYY-M-into-Date/m-p/395792#M95518</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-13T22:48:52Z</dc:date>
    </item>
  </channel>
</rss>

