<?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: Variable is defined as both character and numeric. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741409#M231764</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380276"&gt;@anandmgjsa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Can you cut/paste the actual log&lt;/LI&gt;
&lt;LI&gt;The error message you typed states: "&lt;SPAN&gt;variable &lt;FONT color="#FF0000"&gt;hardate&lt;/FONT&gt; has..." I'm assuming that's a typo and it should be chardate.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;What is the type (char|num) and format date variable on your input data sets?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Assuming it's chardate and the date variable on your input data sets is character in the format "yymmdd10." then the following should work:&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;data got ;
	infile cards;
	input date $10. ;
cards;
20210505
20210510
;

data want ;
	set got (rename=(date=chardate));
	put chardate= ;
	date = input(chardate,yymmdd10.);
	put date= date= date. ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 May 2021 12:38:49 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2021-05-14T12:38:49Z</dc:date>
    <item>
      <title>Variable is defined as both character and numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741394#M231760</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the below code :&lt;/P&gt;&lt;P&gt;data report_week_oct_dec_data;&lt;/P&gt;&lt;P&gt;set report_04_01_2021(rename=(date = chardate))&amp;nbsp;report_11_01_2021(rename=(date = chardate))&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;report_18_01_2021(rename=(date = chardate))&amp;nbsp;report_25_01_2021(rename=(date = chardate))&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; report_28_12_2020(rename=(date = chardate))&lt;/P&gt;&lt;P&gt;if not missing(chardate) then date = input(chardate,yymmdd10.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is throwing error. Error is : variable hardate has been defined as bth character and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 12:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741394#M231760</guid>
      <dc:creator>anandmgjsa</dc:creator>
      <dc:date>2021-05-14T12:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Variable is defined as both character and numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741409#M231764</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380276"&gt;@anandmgjsa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Can you cut/paste the actual log&lt;/LI&gt;
&lt;LI&gt;The error message you typed states: "&lt;SPAN&gt;variable &lt;FONT color="#FF0000"&gt;hardate&lt;/FONT&gt; has..." I'm assuming that's a typo and it should be chardate.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;What is the type (char|num) and format date variable on your input data sets?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Assuming it's chardate and the date variable on your input data sets is character in the format "yymmdd10." then the following should work:&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;data got ;
	infile cards;
	input date $10. ;
cards;
20210505
20210510
;

data want ;
	set got (rename=(date=chardate));
	put chardate= ;
	date = input(chardate,yymmdd10.);
	put date= date= date. ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 May 2021 12:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741409#M231764</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-14T12:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Variable is defined as both character and numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741440#M231773</link>
      <description>&lt;P&gt;in the 1st two files, it is best 32. and in the last three files it's char10.&lt;/P&gt;&lt;P&gt;That's a type 0 error, it is chardate.&lt;/P&gt;&lt;P&gt;i can not paste the log as it's on VDI and i can not copy/snip from that.&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 13:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741440#M231773</guid>
      <dc:creator>anandmgjsa</dc:creator>
      <dc:date>2021-05-14T13:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Variable is defined as both character and numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741469#M231778</link>
      <description>&lt;P&gt;You have two issues. First to convert the CHARACTER versions ONLY use the Rename =&amp;nbsp; data set option in the data sets where "date" is character. You are using it on ALL the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, if your "date" is formatted as BEST32 it is not a date either. So I suspect you have something that is numeric and appears as numbers like 20210318. So that needs to be converted to a date instead of just a random number. So you need to tell SAS which data sets DATE is numeric with best32 format so you can make that consistent. You can use the dataset option IN= to create variable that indicates which data set values are coming from.&lt;/P&gt;
&lt;P&gt;Assuming your "first two sets" means the first two on the SET statement:&lt;/P&gt;
&lt;PRE&gt;data report_week_oct_dec_data;
   set report_04_01_2021(In=in1) 
         report_11_01_2021(in=in2)
         report_18_01_2021(rename=(date = chardate))
         report_25_01_2021(rename=(date = chardate)) 
         report_28_12_2020(rename=(date = chardate))
    ;
   if not missing(chardate) then date = input(chardate,yymmdd10.);
   if in1 or in2 then date = input(put(date,f8. -L),yymmdd10.);
   format date yymmdd10.;
run;&lt;/PRE&gt;
&lt;P&gt;The IN= variables are numeric 1/0 with 1 indicating the current record comes from the data set with that variable. The variables are temporary which means they will not be written to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PLEASE paste code or log entries into a TEXT box opened on the forum with the &amp;lt;/&amp;gt; icon. The main message windows reformat text and can insert non-visible characters that means the code will not run or generate odd errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suspect someone is reading data with Proc Import and not paying attention to details. If you are going to read a bunch of files that are supposed to have the same structure you should be reading the data with a data step to control properties so you don't have to keep "fixing" stuff like this.&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 14:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741469#M231778</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-14T14:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable is defined as both character and numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741481#M231786</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380276"&gt;@anandmgjsa&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;points out the input data sets (report_*) have different types for date (numeric for the first 2 and character for the others).&amp;nbsp;&lt;BR /&gt;I would recommend that you fix this at the source, you probably have a data|proc step somewhere that is creating the report_* data sets, and they really should be created with the same format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 15:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-is-defined-as-both-character-and-numeric/m-p/741481#M231786</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-14T15:37:15Z</dc:date>
    </item>
  </channel>
</rss>

