<?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 Character to Date format in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710698#M26801</link>
    <description>&lt;P&gt;Reading in my raw data set, I have a date variable that is character. An example of a date value is 20150127. I would like to create a new variable that has a date format. Among other things, I have attempted to do that in the following bit of code, but the example date I gave (20150127) gets transformed to 20110, which doesn't seem right. (Additionally, I think my WHERE statement or something is misplaced, because I ultimately end up with the error:&amp;nbsp;ERROR: Variable DDI_d is not on file WORK.DATA_1. And the error:&amp;nbsp; ERROR: Variable DDI_d is not on file WORK.DATA_2. Can anyone help determine what's going on?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data_final;
	merge data_1 data_2;
	by ID;
	if DDI ne "" then do;
		DDI_d = input (DDI,yymmdd10.);
	end;
	else do; 
		DDI_d="";
	end;
	where '1JUL2019'd&amp;lt;=DDI&amp;lt;='30JUN2020'd;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jan 2021 22:35:18 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2021-01-11T22:35:18Z</dc:date>
    <item>
      <title>Character to Date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710698#M26801</link>
      <description>&lt;P&gt;Reading in my raw data set, I have a date variable that is character. An example of a date value is 20150127. I would like to create a new variable that has a date format. Among other things, I have attempted to do that in the following bit of code, but the example date I gave (20150127) gets transformed to 20110, which doesn't seem right. (Additionally, I think my WHERE statement or something is misplaced, because I ultimately end up with the error:&amp;nbsp;ERROR: Variable DDI_d is not on file WORK.DATA_1. And the error:&amp;nbsp; ERROR: Variable DDI_d is not on file WORK.DATA_2. Can anyone help determine what's going on?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data_final;
	merge data_1 data_2;
	by ID;
	if DDI ne "" then do;
		DDI_d = input (DDI,yymmdd10.);
	end;
	else do; 
		DDI_d="";
	end;
	where '1JUL2019'd&amp;lt;=DDI&amp;lt;='30JUN2020'd;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 22:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710698#M26801</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2021-01-11T22:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710701#M26802</link>
      <description>I suspect the value is correct, you just need to apply a format. &lt;BR /&gt;Add this line to your data step and re-run it.&lt;BR /&gt;&lt;BR /&gt;format ddi_d yymmdd10.;</description>
      <pubDate>Mon, 11 Jan 2021 22:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710701#M26802</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-11T22:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710706#M26803</link>
      <description>&lt;P&gt;Is DDI_d in Data_1? Where statements apply to values that already exist in the source data set(s). Your code does not show that variable on the Where statement shown so sort have to guess. Since you show DDI on your where statement I would expect the error to be more like:&lt;/P&gt;
&lt;PRE&gt;5    data example;
6      set data_1;
7       where '1JUL2019'd&amp;lt;=DDI&amp;lt;='30JUN2020'd;
ERROR: WHERE clause operator requires compatible variables.
8    run;
&lt;/PRE&gt;
&lt;P&gt;because date literals are numeric and your DDI variable is stated to be character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best practice on this forum is when you have a question about an error, warning or note to copy from the LOG the entire data step or procedure that generates the message along with &lt;STRONG&gt;all&lt;/STRONG&gt; error, notes and warning messages and then paste the whole thing into a text box opened on the forum using the &amp;lt;/&amp;gt; icon at the top of the message box. The text box preserves the formatting of any of the diagnostic characters SAS often supplies with errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to filter on what may be the newly created variable DDI_d then use:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;IF&lt;/STRONG&gt;&lt;/FONT&gt; '1JUL2019'd&amp;lt;=DDI_d&amp;lt;='30JUN2020'd;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 23:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Date-format/m-p/710706#M26803</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-11T23:21:16Z</dc:date>
    </item>
  </channel>
</rss>

