<?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: Convert the datatype of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369117#M88079</link>
    <description>&lt;P&gt;You can not change the type of a variable once it has been created, but you can use the INPUT/PUT function to create a new variable from the original one with a different type.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jun 2017 12:38:24 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-06-21T12:38:24Z</dc:date>
    <item>
      <title>Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369106#M88070</link>
      <description>&lt;P&gt;I am connecting to oracle to create a SAS work table&lt;BR /&gt;temp using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table temp as&lt;BR /&gt;select distinct id,emp_id &amp;nbsp;from DATA_EXCL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the id field in data_excl oracle table is varchar. So SAS is assigning this column 'char' value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i then merge it with my main SAS table i have the rec_id field as numeric. This is creating an error while merging.&lt;/P&gt;&lt;P&gt;How do i convert the datatype of a variable fetched using proc sql ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents output:&lt;/P&gt;&lt;P&gt;# Variable Type Len Format Informat Label&lt;/P&gt;&lt;P&gt;2 ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Num 8 &amp;nbsp; &amp;nbsp; &amp;nbsp;10. &amp;nbsp;10. &amp;nbsp; ID&lt;BR /&gt;1 EMP_ID &amp;nbsp; &amp;nbsp;Char 15 &amp;nbsp;$15. &amp;nbsp;$15. EMP_ID&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369106#M88070</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2017-06-21T12:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369108#M88072</link>
      <description>&lt;P&gt;Same as any other timme. &amp;nbsp;If you want to do it i SQL then:&lt;/P&gt;
&lt;P&gt;select input(char_var,best.) as num_var&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In dataset:&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;num_var=input(char_var,best.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your doing passthrough, then you would need to use the cast function, though thats outside the scope here.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369108#M88072</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-21T12:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369112#M88076</link>
      <description>&lt;P&gt;You can't really change the type of a variable in either Oracle or SAS. Numerics cannot be converted to character, and vice versa. (You could create a new variable that has the different type ...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can compare the IDs without explicitly converting, for example, something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id = input(emp_id,12.)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will compare the numeric ID to the character EMP_ID (but beware that a character variable can have leading zeros which would cause this comparision to fail)&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369112#M88076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-21T12:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369115#M88078</link>
      <description>&lt;P&gt;Try next code to covert the char into numeric varaible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table temp as
select distinct id,
          input(emp_id,best15.) as emp_id from DATA_EXCL;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369115#M88078</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-21T12:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369117#M88079</link>
      <description>&lt;P&gt;You can not change the type of a variable once it has been created, but you can use the INPUT/PUT function to create a new variable from the original one with a different type.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369117#M88079</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-21T12:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369119#M88081</link>
      <description>&lt;P&gt;Thank you! make sense now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369119#M88081</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2017-06-21T12:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the datatype of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369121#M88083</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you need to compare the char emp_id with the numeric id then you can:&lt;/P&gt;&lt;P&gt;-convert emp_id to num&lt;/P&gt;&lt;P&gt;-or convert id to char&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The type change can be done directly in the ON clause:&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   SELECT b.*
   FROM DATA_EXCL a
   INNER JOIN mainSASTable b
   ON strip(a.emp_id) eq strip(put(b.id,best32.))
   ;
QUIT;&lt;/PRE&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/590.html" target="_blank"&gt;Sample 24590: Convert variable values from character to numeric or from numeric to character&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 12:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-the-datatype-of-a-variable/m-p/369121#M88083</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2017-06-21T12:45:43Z</dc:date>
    </item>
  </channel>
</rss>

