<?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: Need help converting multiple variables from Character to numeric- follow up question in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514118#M2650</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Sat, 17 Nov 2018 12:50:05 GMT</pubDate>
    <dc:creator>RaginiS</dc:creator>
    <dc:date>2018-11-17T12:50:05Z</dc:date>
    <item>
      <title>Need help converting multiple variables from Character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514042#M2632</link>
      <description>&lt;P&gt;Hi, I am super new to SAS programming and need help,&lt;/P&gt;&lt;P&gt;I have a large SAS dataset of property prices information and I need to convert about 3 columns from character to numeric by assigning values 1,2.3….&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;for one column for HeatingAC – I need to put Yes-1 and No as 0&lt;/LI&gt;&lt;LI&gt;For ExternalQuality and KitchenQuality- I need to use 5- for Excellent, 4-Good, 3-Average, 2-Fair, 1-Poor.&lt;/LI&gt;&lt;LI&gt;Dwellingtype- 1-Singlefamily, 2-Twofamily, 3-Duplex and so on;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I tried doing all of this is one temporary dataset but it shows errors, please help. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 19:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514042#M2632</guid>
      <dc:creator>RaginiS</dc:creator>
      <dc:date>2018-11-16T19:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514052#M2636</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/246935"&gt;@RaginiS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I am super new to SAS programming and need help,&lt;/P&gt;
&lt;P&gt;I have a large SAS dataset of property prices information and I need to convert about 3 columns from character to numeric by assigning values 1,2.3….&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;for one column for HeatingAC – I need to put Yes-1 and No as 0&lt;/LI&gt;
&lt;LI&gt;For ExternalQuality and KitchenQuality- I need to use 5- for Excellent, 4-Good, 3-Average, 2-Fair, 1-Poor.&lt;/LI&gt;
&lt;LI&gt;Dwellingtype- 1-Singlefamily, 2-Twofamily, 3-Duplex and so on;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;I tried doing all of this is one temporary dataset but it shows errors, please help. Thanks!&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show what you tried, your code and the log. You likely have a small issue that's easy to correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Video tutorial is here. Ensure you create NEW variables to hold the new values as well, you cannot change the type of a variable on in the same data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?autoStart=true&amp;amp;page=1" target="_blank"&gt;https://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?autoStart=true&amp;amp;page=1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 20:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514052#M2636</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-16T20:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514061#M2640</link>
      <description>&lt;P&gt;Hi, This is what I have so far and it does not work-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname Home '/folders/myfolders/home';&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set home.realestate (rename=(HeatingAC=oldvar));&lt;BR /&gt;if oldvar = 'N' then&amp;nbsp;HeatingAC&amp;nbsp;= 0;&lt;BR /&gt;else HeatingAC= 1;&lt;BR /&gt;drop oldvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set home.realestate ;&lt;BR /&gt;array clean{*} $ _character_;&lt;/P&gt;&lt;P&gt;do i=1 to dim(clean);&lt;/P&gt;&lt;P&gt;if clean{i}='SingleFamily' then&lt;BR /&gt;clean{i}= 1;&lt;/P&gt;&lt;P&gt;if clean{i}='TwoFamily' then&lt;BR /&gt;clean{i}=2;&lt;/P&gt;&lt;P&gt;if clean{i}='Duplex' then&lt;BR /&gt;clean{i}=3;&lt;/P&gt;&lt;P&gt;if clean{i}='Townhome' then&lt;BR /&gt;clean{i}=4;&lt;/P&gt;&lt;P&gt;if clean{i}='Condo' then&lt;BR /&gt;clean{i}=5;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;drop i;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;proc print data=test1;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 22:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514061#M2640</guid>
      <dc:creator>RaginiS</dc:creator>
      <dc:date>2018-11-16T22:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514064#M2642</link>
      <description>&lt;P&gt;Either combine your steps or make sure they don't all start from the original file (realestate). If they do, they're unique files and the changes made don't carry over. I think this is what you were trying to&amp;nbsp; do, changes are in red.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test1;
set home.realestate (rename=(HeatingAC=oldvar));
if oldvar = 'N' then HeatingAC = 0;
else HeatingAC= 1;
drop oldvar;
run;


&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;data test2;
set test1 ;&lt;/STRONG&gt;&lt;/FONT&gt;
array clean{*} $ _character_;  &lt;FONT color="#800080"&gt;&lt;STRONG&gt;*are you sure you want all character variables here;&lt;/STRONG&gt;&lt;/FONT&gt;

do i=1 to dim(clean);

if clean{i}='SingleFamily' then clean{i}= 1;
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt;&lt;/FONT&gt; clean{i}='TwoFamily' then clean{i}=2;
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;else if&lt;/FONT&gt;&lt;/STRONG&gt; clean{i}='Duplex' then clean{i}=3;
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;else if&lt;/FONT&gt;&lt;/STRONG&gt; clean{i}='Townhome' then clean{i}=4;
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;else if&lt;/FONT&gt; &lt;/STRONG&gt;clean{i}='Condo' then clean{i}=5;

end;

drop i;
RUN;

proc print data=&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;test2;&lt;/STRONG&gt;&lt;/FONT&gt;
run;&lt;/PRE&gt;
&lt;P&gt;Let me know if that gets you closer. I'm not sure that using _character_ here makes sense, it will use all character variables including an ID or anything else.&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/246935"&gt;@RaginiS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, This is what I have so far and it does not work-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname Home '/folders/myfolders/home';&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set home.realestate (rename=(HeatingAC=oldvar));&lt;BR /&gt;if oldvar = 'N' then&amp;nbsp;HeatingAC&amp;nbsp;= 0;&lt;BR /&gt;else HeatingAC= 1;&lt;BR /&gt;drop oldvar;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set home.realestate ;&lt;BR /&gt;array clean{*} $ _character_;&lt;/P&gt;
&lt;P&gt;do i=1 to dim(clean);&lt;/P&gt;
&lt;P&gt;if clean{i}='SingleFamily' then&lt;BR /&gt;clean{i}= 1;&lt;/P&gt;
&lt;P&gt;if clean{i}='TwoFamily' then&lt;BR /&gt;clean{i}=2;&lt;/P&gt;
&lt;P&gt;if clean{i}='Duplex' then&lt;BR /&gt;clean{i}=3;&lt;/P&gt;
&lt;P&gt;if clean{i}='Townhome' then&lt;BR /&gt;clean{i}=4;&lt;/P&gt;
&lt;P&gt;if clean{i}='Condo' then&lt;BR /&gt;clean{i}=5;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;drop i;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;proc print data=test1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 22:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514064#M2642</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-16T22:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514071#M2643</link>
      <description>&lt;P&gt;Thank you, that worked&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 22:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514071#M2643</guid>
      <dc:creator>RaginiS</dc:creator>
      <dc:date>2018-11-16T22:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric- follow up question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514080#M2644</link>
      <description>&lt;P&gt;Quick question, I was able to covert the character variables to numeric, I can see it when I run proc print but when I run proc contents it still shows as Char, what did I not do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 00:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514080#M2644</guid>
      <dc:creator>RaginiS</dc:creator>
      <dc:date>2018-11-17T00:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric- follow up question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514092#M2647</link>
      <description>You cannot change variable types on the fly. You need to assign it to new variables, so just duplicate your array with a set of new names and those can be numeric.</description>
      <pubDate>Sat, 17 Nov 2018 02:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514092#M2647</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-17T02:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help converting multiple variables from Character to numeric- follow up question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514118#M2650</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 12:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-converting-multiple-variables-from-Character-to/m-p/514118#M2650</guid>
      <dc:creator>RaginiS</dc:creator>
      <dc:date>2018-11-17T12:50:05Z</dc:date>
    </item>
  </channel>
</rss>

