<?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: Error: Variable has been defined as both character and numeric in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524915#M4867</link>
    <description>&lt;P&gt;You have to check ALL of the common variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy what is to use PROC COMPARE.&amp;nbsp; Use OBS=0 dataset options to prevent it from actually checking the data.&lt;/P&gt;
&lt;P&gt;Let's setup up some example datasets with incompatible variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1 (rename=(name=var1)) test2 (rename=(age=var1));
  set sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's use PROC COMPARE to compare the two datasets. In this case they are named TEST1 and TEST2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=test1(obs=0) compare=test2(obs=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looking at the output you can see this summary of the mis-matched variables.&lt;/P&gt;
&lt;PRE&gt;Data Set Summary

Dataset              Created          Modified  NVar    NObs

WORK.TEST1  06JAN19:12:24:39  06JAN19:12:24:39     5      19
WORK.TEST2  06JAN19:12:24:39  06JAN19:12:24:39     5      19


Variables Summary

Number of Variables in Common: 4.
Number of Variables in WORK.TEST1 but not in WORK.TEST2: 1.
Number of Variables in WORK.TEST2 but not in WORK.TEST1: 1.
Number of Variables with Conflicting Types: 1.


Listing of Common Variables with Conflicting Types

Variable  Dataset     Type  Length

var1      WORK.TEST1  Char       8
          WORK.TEST2  Num        8
&amp;#12;
&lt;/PRE&gt;</description>
    <pubDate>Sun, 06 Jan 2019 17:27:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-01-06T17:27:19Z</dc:date>
    <item>
      <title>Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524899#M4863</link>
      <description>&lt;P&gt;Hi, I just started picking up SAS recently and am working on an assignment. I encountered a problem when trying to merge two data sets together using a variable that appears in both data sets, the error says that the variable has been defined as both character and numeric, but when I checked both data sets, the variable is of character type in both. Hence, I am not sure what exactly could the problem be. Could anyone kindly explain?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524899#M4863</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-06T16:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524902#M4864</link>
      <description>&lt;P&gt;Welcome to the SAS community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; How have you checked the two data sets?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524902#M4864</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-06T16:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524912#M4866</link>
      <description>&lt;P&gt;This happens if a variable is of character type in one data set and numeric in another.&lt;/P&gt;&lt;P&gt;Please have a uniform data type or considering converting both to the same type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 17:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524912#M4866</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2019-01-06T17:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524915#M4867</link>
      <description>&lt;P&gt;You have to check ALL of the common variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy what is to use PROC COMPARE.&amp;nbsp; Use OBS=0 dataset options to prevent it from actually checking the data.&lt;/P&gt;
&lt;P&gt;Let's setup up some example datasets with incompatible variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1 (rename=(name=var1)) test2 (rename=(age=var1));
  set sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's use PROC COMPARE to compare the two datasets. In this case they are named TEST1 and TEST2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=test1(obs=0) compare=test2(obs=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looking at the output you can see this summary of the mis-matched variables.&lt;/P&gt;
&lt;PRE&gt;Data Set Summary

Dataset              Created          Modified  NVar    NObs

WORK.TEST1  06JAN19:12:24:39  06JAN19:12:24:39     5      19
WORK.TEST2  06JAN19:12:24:39  06JAN19:12:24:39     5      19


Variables Summary

Number of Variables in Common: 4.
Number of Variables in WORK.TEST1 but not in WORK.TEST2: 1.
Number of Variables in WORK.TEST2 but not in WORK.TEST1: 1.
Number of Variables with Conflicting Types: 1.


Listing of Common Variables with Conflicting Types

Variable  Dataset     Type  Length

var1      WORK.TEST1  Char       8
          WORK.TEST2  Num        8
&amp;#12;
&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Jan 2019 17:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524915#M4867</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-06T17:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524967#M4877</link>
      <description>Thank you! :)The details of the variables and type was provided.</description>
      <pubDate>Mon, 07 Jan 2019 03:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524967#M4877</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-07T03:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524968#M4878</link>
      <description>It's weird because all of the data sets that contains the same variable is of character type, thank you, I will try converting the type.</description>
      <pubDate>Mon, 07 Jan 2019 03:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524968#M4878</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-07T03:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524969#M4879</link>
      <description>Well I would suggest you use proc compare as mentioned by tom or use proc content . This would help you decide your next steps.&lt;BR /&gt;Make sure the are identical - type, length, format .&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Jan 2019 03:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524969#M4879</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2019-01-07T03:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524971#M4880</link>
      <description>&lt;P&gt;Thank you, I have found out the problem but it's weird because it was detailed as a character type for both data sets in the data dictionary that was provided. In this case how should I do the conversion?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  Variables Summary                                                          
                                                                                                                                    
                                   Number of Variables in Common: 1.                                                                
                                   Number of Variables in WORK.ACCOUNT but not in WORK.LOAN: 3.                                   
                                   Number of Variables in WORK.LOAN but not in WORK.ACCOUNT: 6.                                   
                                   Number of Variables with Conflicting Types: 1.                                                   

                                                         
                                                                                                                                    
                                         Listing of Common Variables with Conflicting Types                                         
                                                                                                                                    
                               Variable    Dataset        Type  Length  Format   Informat  Label                                    
                                                                                                                                    
                               account_id  WORK.ACCOUNT  Char       5  $CHAR5.  $CHAR5.                                            
                                           WORK.LOAN     Num        8  BEST.              account_id                               
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 04:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524971#M4880</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-07T04:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524972#M4881</link>
      <description>Alright, thank you!</description>
      <pubDate>Mon, 07 Jan 2019 04:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524972#M4881</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-07T04:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524974#M4882</link>
      <description>&lt;P&gt;So the dataset LOAN was created incorrectly if the variable ACCOUNT_ID is supposed to be a character variable.&lt;/P&gt;
&lt;P&gt;How did you create the dataset?&amp;nbsp; Can you fix that step?&lt;/P&gt;
&lt;P&gt;It MIGHT be possible to convert the number back to a character string, but perhaps not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example what if you have the number 11 what string should you convert it to?&amp;nbsp; Did the original value have leading zeros?&amp;nbsp; If so how many?&lt;/P&gt;
&lt;P&gt;Also what if the original value for ACCOUNT_ID had a letter in it?&amp;nbsp; There is no way that got converted to a number, so the value is now lost.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 05:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524974#M4882</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-07T05:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524977#M4883</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set wasn't created by me, it was provided, it was purposely created this way to be solved. I didn't realise that it was created wrongly previously.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="This is the column in Account" style="width: 130px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26031iA49C9A4D6EE84ED9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ACCOUNT.png" alt="This is the column in Account" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;This is the column in Account&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="This is the column in Loan" style="width: 96px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26032i86E1DD5F05F98B7F/image-size/large?v=v2&amp;amp;px=999" role="button" title="LOAN.png" alt="This is the column in Loan" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;This is the column in Loan&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 05:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/524977#M4883</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-07T05:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525228#M4910</link>
      <description>&lt;P&gt;Welcome to the world of (almost) real data where folks tell you one thing about their data and you get to determine they weren't really sure of what they had.&lt;/P&gt;
&lt;P&gt;Your choice is to decide which variable type you want to use going forward. If a variable is an identifier that you aren't going to do arithmetic with then likely the character version is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a code template for fixing such issues with a single variable that needs to go from numeric to character:&lt;/P&gt;
&lt;PRE&gt;data fixed;
   set have (rename=(account=accountnum));
   length account $ 5.;
   account= put(accountnum,f5. -L);
   drop accountnum;
run;&lt;/PRE&gt;
&lt;P&gt;The rename in the data set option allows you to use the value of the old variable but create a new variable of the desired name. SAS will not let you change variable types directly. Many have tried and many have failed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To minimize possibly confusion explicitly specify the length of the character variable before use.&lt;/P&gt;
&lt;P&gt;The put function with the -L left justifies the string in the result, otherwise you are likely to get leading spaces.&lt;/P&gt;
&lt;P&gt;Then drop the old value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to go from character to numeric then the function would be INPUT instead of Put and the Length statement is likely not needed. You would need an appropriate informat to match you value type.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 21:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525228#M4910</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-07T21:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525445#M4973</link>
      <description>Thank you so much!</description>
      <pubDate>Tue, 08 Jan 2019 15:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525445#M4973</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-08T15:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525492#M4982</link>
      <description>&lt;P&gt;One additional bit about the Format used for the PUT function. If your character values have leading zero you may want to use a Z format instead of F. That would come into play generally with fixed length identifiers such as 00543 where all of the values are padded with leading zeroes to a given length. If you have intermittent leading 0 without an explicit rule regarding what values may require them then matching the ID variables may get to be a problem.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 16:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525492#M4982</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-08T16:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Variable has been defined as both character and numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525755#M5010</link>
      <description>Ohh, thank you very much!</description>
      <pubDate>Wed, 09 Jan 2019 16:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/525755#M5010</guid>
      <dc:creator>XY7</dc:creator>
      <dc:date>2019-01-09T16:09:20Z</dc:date>
    </item>
  </channel>
</rss>

