<?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: Trouble converting Character variable into Numeric to apply a user-defined format. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697447#M25405</link>
    <description>&lt;P&gt;Hello, they are not. The data set is fake and is for a class.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Nov 2020 17:08:43 GMT</pubDate>
    <dc:creator>GoldingAngela</dc:creator>
    <dc:date>2020-11-08T17:08:43Z</dc:date>
    <item>
      <title>Trouble converting Character variable into Numeric to apply a user-defined format.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697395#M25395</link>
      <description>&lt;P&gt;I am trying to convert the character variable "GenderCd" to a numeric variable. In order to apply a numeric format 'GenderCd.' I have tried using the INPUT statement to convert the variable into a numeric one, but it doesn't seem to be working properly. I'm not sure what I'm doing incorrectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is the following code I've input into SAS:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;DATA WORK.Demog_IA;&lt;/P&gt;&lt;P&gt;KEEP SSN GenderCd EthCd RaceCd EthRaceCd BirthDt;&lt;/P&gt;&lt;P&gt;SET IowaResidents;&lt;/P&gt;&lt;P&gt;LENGTH SSN $11&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GenderCd&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EthCd $1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RaceCd $1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EthRaceCd $3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gender = INPUT(Sex,1.);&lt;BR /&gt;Gender= PROPCASE(Sex);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF Gender = 'Male' THEN GenderCd = 1;&lt;BR /&gt;ELSE IF Gender = 'Female' Then GenderCd = 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF MISSING(Ethnicity) = 1 THEN EthCd = ' ';&lt;BR /&gt;ELSE IF Ethnicity = 'HISPANIC' THEN EthCd = 'H';&lt;BR /&gt;ELSE IF Ethnicity = 'NON-HISPANIC' THEN EthCd = 'N';&lt;BR /&gt;Else EthCd = 'U';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF MISSING(Race) = 1 THEN RaceCd = ' ';&lt;BR /&gt;ELSE IF Race = 'WHITE' THEN RaceCd = 'W';&lt;BR /&gt;ELSE IF Race = 'BLACK' THEN RaceCd = 'B';&lt;BR /&gt;ELSE IF Race = 'ASIAN' THEN RaceCd = 'A';&lt;BR /&gt;ELSE IF Race = 'OTHER' THEN RaceCd = 'O';&lt;BR /&gt;ELSE RaceCd = 'U';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF MISSING(EthCd) = ' ' AND RaceCd = ' ' THEN EthRaceCd = ' ';&lt;BR /&gt;ELSE IF EthCd = 'H' THEN EthRaceCd = 'HIS';&lt;BR /&gt;ELSE IF RaceCd = 'A' THEN EthRaceCd = 'NHA';&lt;BR /&gt;ELSE IF RaceCd = 'B' THEN EthRaceCd = 'NHB';&lt;BR /&gt;ELSE IF RaceCd = 'W' THEN EthRaceCd = 'NHW';&lt;BR /&gt;ELSE IF RaceCd = 'O' THEN EthRaceCd = 'NHO';&lt;BR /&gt;ELSE EthRaceCd = '.';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA = WORK.Demog_IA;&lt;BR /&gt;FORMAT GenderCd GenderCd.&lt;BR /&gt;EthCd $EthCd.&lt;BR /&gt;RaceCd $RaceCd.&lt;BR /&gt;EthRaceCd $EthRaceCd.&lt;BR /&gt;BirthDt MMDDYY10.;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When I attempt to apply the format to the variables I receive the following error message:&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class="sasError"&gt;ERROR: You are trying to use the numeric format GENDERCD with the character variable GenderCd in data set WORK.DEMOG_IA.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697395#M25395</guid>
      <dc:creator>GoldingAngela</dc:creator>
      <dc:date>2020-12-10T15:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble converting Character variable into Numeric to apply a user-defined format.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697396#M25396</link>
      <description>&lt;P&gt;Gendercd, as you sais, is char type.&lt;/P&gt;
&lt;P&gt;According to log&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;"You are trying to use the numeric format GENDERCD with the character variable GenderCd in data set"&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;But your numeric variable is GENDER [in code:&amp;nbsp;&lt;SPAN&gt;Gender = INPUT(Sex,1.);]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Change the line in proc print to:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FORMAT Gender GenderCd.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;instead:&amp;nbsp;FORMAT GenderCd GenderCd.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and add VAR statement to define the variables to print and their order.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 04:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697396#M25396</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-08T04:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble converting Character variable into Numeric to apply a user-defined format.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697398#M25397</link>
      <description>&lt;P&gt;Are those real SSNs in your screenshot? If so you should consider removing them for privacy reasons.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 05:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697398#M25397</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-11-08T05:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble converting Character variable into Numeric to apply a user-defined format.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697447#M25405</link>
      <description>&lt;P&gt;Hello, they are not. The data set is fake and is for a class.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 17:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697447#M25405</guid>
      <dc:creator>GoldingAngela</dc:creator>
      <dc:date>2020-11-08T17:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble converting Character variable into Numeric to apply a user-defined format.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697448#M25406</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LENGTH SSN $11
               &lt;FONT color="#FF0000"&gt;GenderCd&lt;/FONT&gt; /* by not supplying anything here, gendercd will be defined as $1, along with ethcd */
               EthCd $1
               RaceCd $1
               EthRaceCd $3;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Nov 2020 17:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-converting-Character-variable-into-Numeric-to-apply-a/m-p/697448#M25406</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-08T17:57:18Z</dc:date>
    </item>
  </channel>
</rss>

