<?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 date field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824270#M325510</link>
    <description>&lt;P&gt;You are absolutely brilliant, this is exactly what I needed. Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2022 01:18:24 GMT</pubDate>
    <dc:creator>mmaximos</dc:creator>
    <dc:date>2022-07-20T01:18:24Z</dc:date>
    <item>
      <title>SAS date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824267#M325507</link>
      <description>&lt;P&gt;I have a variable that I've named time_period which contains dates listed in the following format as a numeric variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;201511
201511
201612
201701
201701
...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;SAS reads these as a "SAS date" and therefore converts 201511 (which is intended to be Nov 2015) to&amp;nbsp;Sep 20, 2511.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found this out when I tried formatting to a word date so I can understand how SAS was reading it:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data mydata; 
	set sample;
    sasdate=input(time_period, YYMON.); /*YYMMDDw.*/
    format sasdate worddate12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;From what I understand, I need to take this numeric value and convert it to a date value. Some responses explain that you need to ad an "01" in the code to act as a "dd", so I tried the following:&lt;/P&gt;&lt;PRE&gt;data cdiff.date;&lt;BR /&gt;set cdiff.c;&lt;BR /&gt;format sasdate date9.;&lt;BR /&gt;sasdate = input(time_period !! "01", yymmdd8.);&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;This did not work, the output is "." down the entire column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other examples suggest adding a specific date in the date field (I think), but that replaces all the dates with this specific date in my new column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to approach this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 01:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824267#M325507</guid>
      <dc:creator>mmaximos</dc:creator>
      <dc:date>2022-07-20T01:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824269#M325509</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think operators (like !!) are allow in arguments to the INPUT function, but the CATS function is.&amp;nbsp; Use&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;  sasdate=input(cats(time_period,'01'),yymmdd8.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 01:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824269#M325509</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-20T01:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824270#M325510</link>
      <description>&lt;P&gt;You are absolutely brilliant, this is exactly what I needed. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 01:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824270#M325510</guid>
      <dc:creator>mmaximos</dc:creator>
      <dc:date>2022-07-20T01:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824282#M325518</link>
      <description>&lt;P&gt;If you have numbers like 201,511 and you want to convert that to the date 01NOV2015 there are a number of ways.&lt;/P&gt;
&lt;P&gt;You could use arithmetic to extract the YEAR and MONTH values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = mdy(int(number/100),1,mod(number,100));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could convert the number to a string and use the YYMMN informat to convert it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=input(put(number,z6.),yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have a date value attach any date type format you want to display it in a way that humans can understand, preferably one that will not be confused for a number like the 201,511 you started with.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 05:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824282#M325518</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-20T05:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824366#M325566</link>
      <description>&lt;P&gt;Possibly go back to your step where you read the data into SAS and read that variable with the YYMMN. informat at the beginning so the value starts as a date. The YYMMN. informat will treat the resulting date as the first day of the month.&lt;/P&gt;
&lt;PRE&gt;data example;
   input date :yymmn.;
   format date yymmdd10.;
datalines;
201511
201511
201612
201701
201701
;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2022 14:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-field/m-p/824366#M325566</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-20T14:20:09Z</dc:date>
    </item>
  </channel>
</rss>

