<?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: Change variable type using type in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549080#M152313</link>
    <description>&lt;P&gt;You can't change the type of an existing variable in SAS, you can only assign the type of new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type do you want Latitude to be in all of your datasets? It would help if you posted a sample of your data.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Apr 2019 02:07:27 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2019-04-07T02:07:27Z</dc:date>
    <item>
      <title>Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549079#M152312</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several data sets that all contain the same variables. Problem is, one date variable is sometimes stored as a numeric variable, sometimes as a character variable.&lt;/P&gt;&lt;P&gt;I tried the following :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if vtype(Latitude) = "N" then Latitude = Latitude;&lt;/P&gt;&lt;P&gt;else Latitude = put(Latitude, 8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I am getting an error:&lt;/P&gt;&lt;P&gt;Variable Latitude has been defined as both character and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 01:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549079#M152312</guid>
      <dc:creator>Nikolasas</dc:creator>
      <dc:date>2019-04-07T01:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549080#M152313</link>
      <description>&lt;P&gt;You can't change the type of an existing variable in SAS, you can only assign the type of new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type do you want Latitude to be in all of your datasets? It would help if you posted a sample of your data.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 02:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549080#M152313</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-04-07T02:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549081#M152314</link>
      <description>&lt;P&gt;Latitude needs to be numeric, so I thought of converting it like that.&lt;/P&gt;&lt;P&gt;I tried writing it as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if vtype(Latitude) = "N" then Latitude1= Latitude;&lt;/P&gt;&lt;P&gt;else Latitude1 = put(Latitude, 8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and dropping, Latitude and renaming Latitiude1 to Latitude, but I get the same error.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 02:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549081#M152314</guid>
      <dc:creator>Nikolasas</dc:creator>
      <dc:date>2019-04-07T02:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549082#M152315</link>
      <description>The PUT function generates a character string, not a numeric.  Use the INPUT function instead.</description>
      <pubDate>Sun, 07 Apr 2019 02:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549082#M152315</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-07T02:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549084#M152316</link>
      <description>&lt;P&gt;Unfortunately it seems you need to know the variable type ahead of time to get this to work without warnings/notes. If warning/notes are fine, it can be done in a single step the would works regardless of input type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the best solution is to have it read in properly in the first place. Did you import text files using PROC IMPORT and are now trying to merge them? Are all the input files formatted exactly the same? If yes, there is a faster way to fix this issue. If not, there are other ways, just a little bit more work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269643"&gt;@Nikolasas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have several data sets that all contain the same variables. Problem is, one date variable is sometimes stored as a numeric variable, sometimes as a character variable.&lt;/P&gt;
&lt;P&gt;I tried the following :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if vtype(Latitude) = "N" then Latitude = Latitude;&lt;/P&gt;
&lt;P&gt;else Latitude = put(Latitude, 8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I am getting an error:&lt;/P&gt;
&lt;P&gt;Variable Latitude has been defined as both character and numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestion?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nick&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 02:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549084#M152316</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-07T02:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change variable type using type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549178#M152362</link>
      <description>&lt;P&gt;Use the CATS() function to convert the current variable into a string. Then use the INPUT() function to convert that to a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
 latitude='56.3';
run;
data want;
  set have;
  number=input(cats(latitude),32.);
  drop latitude;
  rename number=latitude;
run;

data have ;
 latitude=56.3;
run;
data want;
  set have;
  number=input(cats(latitude),32.);
  drop latitude;
  rename number=latitude;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-variable-type-using-type/m-p/549178#M152362</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-08T05:24:36Z</dc:date>
    </item>
  </channel>
</rss>

