<?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: Converting character variable into date variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574991#M162540</link>
    <description>&lt;P&gt;Here are sample values for ADMIT_DTTM:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2017-11-06&lt;/P&gt;&lt;P&gt;2017-10-26&lt;/P&gt;&lt;P&gt;2017-09-06&lt;/P&gt;&lt;P&gt;2017-08-28&lt;/P&gt;&lt;P&gt;2017-11-06&lt;/P&gt;&lt;P&gt;2018-01-23&lt;/P&gt;&lt;P&gt;2018-02-21&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jul 2019 15:47:30 GMT</pubDate>
    <dc:creator>Kbug</dc:creator>
    <dc:date>2019-07-19T15:47:30Z</dc:date>
    <item>
      <title>Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574987#M162537</link>
      <description>&lt;P&gt;Hello, I am using SAS 9.4 and I am trying to convert my character variable into date format.&lt;/P&gt;&lt;P&gt;I have a file named diagnosistest2 and I want to change the variable, ADMIT_DTTM from text to date format. ADMIT_DTTM has 10 characters. I don't quite understand how to do a conversion, but I have tried variations of this code(below) and when I run it it replaces all the values with "."&amp;nbsp; &amp;nbsp; How would I go about fixing my code to make the conversion work?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cdiff.diagnosistest3;
set cdiff.diagnosistest2;
ADMIT_DTTM2=input(ADMIT_DTTM, 10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574987#M162537</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T15:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574990#M162539</link>
      <description>&lt;P&gt;Can you please post a &lt;STRONG&gt;sample of the values&lt;/STRONG&gt; of what your&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;ADMIT_DTTM&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;variable look like?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574990#M162539</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-19T15:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574991#M162540</link>
      <description>&lt;P&gt;Here are sample values for ADMIT_DTTM:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2017-11-06&lt;/P&gt;&lt;P&gt;2017-10-26&lt;/P&gt;&lt;P&gt;2017-09-06&lt;/P&gt;&lt;P&gt;2017-08-28&lt;/P&gt;&lt;P&gt;2017-11-06&lt;/P&gt;&lt;P&gt;2018-01-23&lt;/P&gt;&lt;P&gt;2018-02-21&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574991#M162540</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T15:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574992#M162541</link>
      <description>&lt;P&gt;Ok Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ADMIT_DTTM2=input(ADMIT_DTTM, yymmdd10.);
format ADMIT_DTTM2 yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574992#M162541</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-19T15:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574993#M162542</link>
      <description>&lt;P&gt;What values does your character variable have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current program is assuming that the variable contains digits only.&amp;nbsp; If you want the value to usable as a date then it also needs to represent the number of days counted from 1960.&amp;nbsp; If you are getting only missing values then the first 10 characters of your character variable do not contain a string that represents a number.&amp;nbsp; Perhaps they look like dates with some delimiter between the parts?&amp;nbsp; perhaps like '2019-07-19'?&amp;nbsp; If so then use an appropriate INFORMAT in your INPUT() statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you also mentioned that you want a DATE value, but the name of the variable makes it look like it probably contains DATETIME values instead.&amp;nbsp; &amp;nbsp;DATETIME values are the number of seconds counted from 1960 instead of the number of days that a DATE value would contain.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574993#M162542</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T15:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574995#M162544</link>
      <description>&lt;P&gt;There is an error. 48-59 the format $yymmdd was not found or could not be loaded.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574995#M162544</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T15:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574996#M162545</link>
      <description>&lt;P&gt;Please show us your code&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574996#M162545</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-19T15:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574997#M162546</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cdiff.diagnosistest3;
set cdiff.diagnosistest2;
ADMIT_DTTM2=input(ADMIT_DTTM, yymmdd10.);
format ADMIT_DTTM2 yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574997#M162546</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T15:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574998#M162547</link>
      <description>&lt;P&gt;It has yyyy-mm-dd as the values. So I would use a input statement of some sort then?&lt;BR /&gt;Originally it was yyyy-mm-dd 00:00:00, then I trimmed the string and changed the character length as needed.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/574998#M162547</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T15:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575001#M162548</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281708"&gt;@Kbug&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;There is an error. 48-59 the format $yymmdd was not found or could not be loaded.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you try to attach a format of the wrong type to a variable SAS will silently convert it to the proper type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it looks like you have tried to attach the YYMMDD. format to a character variable.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575001#M162548</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T15:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575002#M162549</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281708"&gt;@Kbug&lt;/a&gt;&amp;nbsp; &amp;nbsp;Here is test, please run and see where's the discrepancy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;


data have;
input date $10.;
cards;
2017-11-06
2017-10-26
2017-09-06
2017-08-28
2017-11-06
2018-01-23
2018-02-21
;

data want;
set have;
new_date=input(date,yymmdd10.);
format new_date yymmdd10.;
run;

proc print data=want nobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 15:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575002#M162549</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-19T15:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575003#M162550</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281708"&gt;@Kbug&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It has yyyy-mm-dd as the values. So I would use a input statement of some sort then?&lt;BR /&gt;Originally it was yyyy-mm-dd 00:00:00, then I trimmed the string and changed the character length as needed.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you use the YYMMDD10. informat then it will convert that into a date value.&amp;nbsp; No need to trim it first since only the first 10 characters will be used by the informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  my_date = input(charvar,yymmdd10.);
  format my_date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 16:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575003#M162550</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T16:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575004#M162551</link>
      <description>&lt;P&gt;It ran successfully, I see that the date changes from 10 char to 8 yymmdd10. The code on the test looks exactly like how it is written on my editor. I don't understand why variable ADMIT_DTTM cannot load the format but the test code can.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 16:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575004#M162551</guid>
      <dc:creator>Kbug</dc:creator>
      <dc:date>2019-07-19T16:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575009#M162554</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281708"&gt;@Kbug&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It ran successfully, I see that the date changes from 10 char to 8 yymmdd10. The code on the test looks exactly like how it is written on my editor. I don't understand why variable ADMIT_DTTM cannot load the format but the test code can.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot change the type of an existing variable.&amp;nbsp; So ADMIT_DTTM is already defined as character.&amp;nbsp; You need to create a new variable that numeric to hold the date value.&amp;nbsp; You can use rename statement or rename= option to change the name if you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  my_date=input(admit_dttm,yymmdd10.);
  format my_date yymmdd10.;
  rename admit_dttm=admit_dttm_char my_date=admit_dttm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as I said before I wouldn't call a variable that has a DATE value with a name that implies it has a DATETIME value. You will just confuse people.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 16:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575009#M162554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T16:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575078#M162595</link>
      <description>&lt;P&gt;How do I convert days to months? Can someone please help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 23:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575078#M162595</guid>
      <dc:creator>Cerium23</dc:creator>
      <dc:date>2019-07-19T23:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable into date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575081#M162596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282171"&gt;@Cerium23&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How do I convert days to months? Can someone please help.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depends on what you mean.&lt;/P&gt;
&lt;P&gt;Normally for generating statistics on number of months I like to just divide number of days by a constant like 30 than worry about the varying number of days in calendar months.&amp;nbsp; To get the difference in days between two dates just subtract them.&lt;/P&gt;
&lt;P&gt;If you want to get real difference of calendar months between two dates you can use the INTCK() function with the MONTH interval.&amp;nbsp; But be careful as it counts the number of boundaries crossed.&amp;nbsp; So a difference of 30 days might return 0,1 or 2 boundaries crossed depending on the actual dates being compared.&lt;/P&gt;
&lt;P&gt;If you just want to get the month within the year from a date value use the MONTH() function.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2019 00:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-variable-into-date-variable/m-p/575081#M162596</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-20T00:08:44Z</dc:date>
    </item>
  </channel>
</rss>

