<?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 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/786288#M32208</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am New to this forum, but I am hoping can get a reply to my question fairly quickly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Requirement :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Import excel file present location into SAS dataset ( file name wave1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note :&amp;nbsp;Excel&amp;nbsp; is refreshed on daily&amp;nbsp; bases&lt;/P&gt;&lt;P&gt;2) Current SAS dataset is an exact replica of the Excel wave1. So if there are any columns missing in excel which was previously present for some reason , these columns will be missing from the SAS dataset too. However, Spotfire marks it as an invalid dataset since few columns are missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To overcome this we have placed previous created SAS dataset in backup folder and using below code retain variable structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After importing into excel file into SAS data set I am using below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set new previous (obs=0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above code work fine sometime and it will throw below error some time&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error : Variable has been defined as both character and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to resolve this error permanently .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Dec 2021 12:29:43 GMT</pubDate>
    <dc:creator>manikanta9500</dc:creator>
    <dc:date>2021-12-16T12:29:43Z</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/786288#M32208</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am New to this forum, but I am hoping can get a reply to my question fairly quickly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Requirement :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Import excel file present location into SAS dataset ( file name wave1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note :&amp;nbsp;Excel&amp;nbsp; is refreshed on daily&amp;nbsp; bases&lt;/P&gt;&lt;P&gt;2) Current SAS dataset is an exact replica of the Excel wave1. So if there are any columns missing in excel which was previously present for some reason , these columns will be missing from the SAS dataset too. However, Spotfire marks it as an invalid dataset since few columns are missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To overcome this we have placed previous created SAS dataset in backup folder and using below code retain variable structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After importing into excel file into SAS data set I am using below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set new previous (obs=0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above code work fine sometime and it will throw below error some time&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error : Variable has been defined as both character and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to resolve this error permanently .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 12:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/786288#M32208</guid>
      <dc:creator>manikanta9500</dc:creator>
      <dc:date>2021-12-16T12:29: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/786291#M32209</link>
      <description>&lt;P&gt;The best way:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;don't accept excel as data source&lt;/LI&gt;
&lt;LI&gt;use csv instead&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;don't use proc import to read csv, but write your own data step&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 16 Dec 2021 13:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/786291#M32209</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-12-16T13:18:56Z</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/786308#M32210</link>
      <description>&lt;P&gt;Proc Import makes guesses as to variable types based on the content of the file. Separately for each file.&lt;/P&gt;
&lt;P&gt;So when you "import" multiple different files that have the same structure because Excel does not enforce any rules as to content of cells you may have different types of data in the same column from different files. So the result is different variable types and different lengths for character variables (which can cause truncation of data).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if someone inserts an additional row of headers that second row of headers now becomes data and you might even have completely different names of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time saving the file to CSV (there are several choices in the Excel menu under File-Save as) will create a text file that a SAS data step can read in a consistent manner. That way all of the variables have the same type, length and properties such as variable name as well for each file. The provider of the files should be able to tell you which columns are supposed to be text and how many characters, which numeric and which date or time values. Then you can set the proper type and properties in the SAS data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Save the file as CSV, run Proc import for the CSV file using the option GUESSINGROWS=MAX to have the procedure look at more rows before guessing the properties for the variables. The LOG will show a generated data step that you can copy to the Editor and clean up: remove line numbers, verify informats (character length and if the type is correct). SAVE that program as a basis for the code. Next file you change the name of the input file and maybe the output SAS data set, depending on how you want to work.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 16:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/786308#M32210</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-16T16:01: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/786324#M32214</link>
      <description>&lt;P&gt;If you expect ANY kind of consistency, then you simply &lt;STRONG&gt;MUST NOT&lt;/STRONG&gt; use Excel files, period.&lt;/P&gt;
&lt;P&gt;Excel files force SAS to make guesses about column attributes, and that can fail for numerous reasons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Set up a data dictionary that clearly and unambiguously describes all columns&lt;/LI&gt;
&lt;LI&gt;Accept only text files as transfer format&lt;/LI&gt;
&lt;LI&gt;Write a data step that reads the files according to the dictionary, and fails with a clear message if invalid data is encountered&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 16 Dec 2021 17:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/786324#M32214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-16T17:35:20Z</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/786415#M32218</link>
      <description>&lt;P&gt;Who is refreshing the EXCEL file? How are they refreshing it?&amp;nbsp; Can you have them create a delimited text file instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you cannot you might try creating the delimited text file yourself.&amp;nbsp; That might let you handle the new files with little change to your current SAS program.&amp;nbsp; Just add a step to write the imported EXCEL file out as text and then read it using the structure of the target.&amp;nbsp; This should fix most of the problems with wrong variable types.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So convert he EXCEL file to a CSV file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='newfile.xlsx' out=newfile replace;
run;
filename csv temp;
data _null_;
  set newfile;
  file csv dsd termstr=crlf ;
  put (_all_) (+0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use a data step to read the CSV file.&amp;nbsp; You could use the structure of your PREVIOUS file to drive the reading.&amp;nbsp; Make sure that proper informats are attached to any variable that might need them.&amp;nbsp; Usually only DATE/TIME or DATETIME variables need special informats, but if you have fields with commas and/or dollar signs that you want read as numbers you need to use the COMMA informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
  if 0 then set previous;
  infile csv dsd truncover termstr=crlf;
  input (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Note this will not work if they change the number or order of the variables (columns) in the file.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 03:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Error-Variable-has-been-defined-as-both-character-and-numeric/m-p/786415#M32218</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-17T03:39:00Z</dc:date>
    </item>
  </channel>
</rss>

