<?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: How do I create a datetime variable using a character year variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897984#M354929</link>
    <description>&lt;P&gt;A date is defined as a specific &lt;U&gt;day&lt;/U&gt; within a specific &lt;U&gt;month&lt;/U&gt; within a specific &lt;U&gt;year&lt;/U&gt;. So you need all three values to get a date value. When you only have a year, you must define a rule for this; this rule can very well be "select a random day", of course.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 16:16:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-10-10T16:16:49Z</dc:date>
    <item>
      <title>How do I create a datetime variable using a character year variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897979#M354924</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable called 'Year' that is a character variable with values like '2007'. How can I convert this to a SAS date? Do I need to add a random month and day like July 2nd to all of the values so that I can convert it using MDY? I'm not sure what the best way to do this is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 15:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897979#M354924</guid>
      <dc:creator>evance1</dc:creator>
      <dc:date>2023-10-10T15:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a datetime variable using a character year variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897980#M354925</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MDY function is possible indeed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is also possible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;        
 jaar = '2007'; 
run;
data b; 
 set a; 
 datum_char = '01JAN'!!strip(jaar); 
 datum_nume = input(datum_char, date9.);
 format datum_nume ddmmyy10.;
run;
proc print data=b; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 16:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897980#M354925</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-10-10T16:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a datetime variable using a character year variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897981#M354926</link>
      <description>&lt;P&gt;Do you want a DATE value (number of days) or a DATETIME value (number of seconds)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What day in the year do you want?&amp;nbsp; If you want a DATETIME value then what time of day on that chosen day?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  year='2017';
run;

data want;
  date = mdy(1,1,input(year,32.));
  datetime = dhms(date,0,0,0);
  format date date9. datetime datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2023 16:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897981#M354926</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-10T16:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a datetime variable using a character year variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897984#M354929</link>
      <description>&lt;P&gt;A date is defined as a specific &lt;U&gt;day&lt;/U&gt; within a specific &lt;U&gt;month&lt;/U&gt; within a specific &lt;U&gt;year&lt;/U&gt;. So you need all three values to get a date value. When you only have a year, you must define a rule for this; this rule can very well be "select a random day", of course.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 16:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897984#M354929</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-10T16:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a datetime variable using a character year variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897991#M354932</link>
      <description>&lt;P&gt;Okay, let me ask the obvious question. If you have a year value, what is the point of converting it to a datetime value? What can you then do with a datetime value that you couldn't do if you left it as a date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, years should be numeric, it makes sense to convert it to a number, 2007. Years should never be character.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 17:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-datetime-variable-using-a-character-year/m-p/897991#M354932</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-10T17:16:06Z</dc:date>
    </item>
  </channel>
</rss>

