<?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 character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886966#M350472</link>
    <description>&lt;P&gt;So that is a different question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does the order the data sorts impact the result of the logistic regression?&amp;nbsp; The only thing I can think of is that it could change which value it considers as the comparison group.&amp;nbsp; Can't you just specify which value to use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What procedure are you using to run logistic regression?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 29 Jul 2023 15:42:29 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-29T15:42:29Z</dc:date>
    <item>
      <title>convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886856#M350423</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to convert the following character values into numeric.&lt;/P&gt;&lt;P&gt;My values are in character;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interst&lt;BR /&gt;Freeway&lt;BR /&gt;Pri Art&lt;BR /&gt;Min Art&lt;BR /&gt;Maj Col&lt;/P&gt;&lt;P&gt;Min Col&lt;BR /&gt;Local&lt;/P&gt;&lt;P&gt;First I want to convert to numeric then convert to 1,2,3 in the following order.&lt;/P&gt;&lt;P&gt;'Interst' = 1&lt;BR /&gt;'Freeway' = 2&lt;BR /&gt;'Pri Art' = 3&lt;BR /&gt;'Min Art' = 4&lt;BR /&gt;'Maj Col' = 5&lt;BR /&gt;'Min Col' = 6&lt;BR /&gt;'Local' = 7&lt;/P&gt;&lt;P&gt;I initially created a format and i ran an input statement in the data step but I didn't get the expected result. My results were blank for funtional_num. Please help!!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc format;
  value $functional  'Interst' = 1
                     'Freeway' = 2
                     'Pri Art' = 3
                     'Min Art' = 4
                     'Maj Col' = 5
                     'Min Col' = 6
                     'Local'   = 7
                     ;
run;
&lt;BR /&gt;data A;
length functional $10.;
input functional$ 1-10;
datalines;
Interst
Freeway
Pri Art
Min Art
Maj Col
Min Col
Local
; run;

data B;
set A;
functional_num = input(functional, 8.);
format functional_num functional.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Result obtained:&lt;/P&gt;&lt;P&gt;Obs functional functional_num&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; Interst&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;Freeway&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; Pri Art&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;4&amp;nbsp; &amp;nbsp;Min Art&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;5&amp;nbsp; &amp;nbsp;Maj Col&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;6&amp;nbsp; &amp;nbsp;Min Col&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;7&amp;nbsp; &amp;nbsp;Local&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886856#M350423</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-07-28T17:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886865#M350426</link>
      <description>&lt;P&gt;Its not clear what you are trying to do here. Normally formats are used to make the data "more readable", converting numbers (such as 1, 2, 3, ...) into something more meaningful to the audience or SAS programmer, such as "Freeway", "Pri Art", ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may have a valid reason why you would want to use the reverse of what I just described and disguise "Freeway" as the number 2, but I am skeptical this is a good thing to do. (There are cases where you are working with somewhat sensitive data, such as ethnicity, and you might want to disguise "Hispanic" as the number 2, but this doesn't seem to apply here).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B;
    set A;
    functional_num = functional;
    format functional_num $functional.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Functional_num is still a character variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If FUNCTIONAL_NUM really has to be numeric, then you need an &lt;FONT color="#FF0000"&gt;IN&lt;/FONT&gt;FORMAT to be used in the INPUT function, not a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue functional  'Interst' = 1
                     'Freeway' = 2
                     'Pri Art' = 3
                     'Min Art' = 4
                     'Maj Col' = 5
                     'Min Col' = 6
                     'Local'   = 7
                     ;
run;

data A;
length functional $10.;
input functional$ 1-10;
datalines;
Interst
Freeway
Pri Art
Min Art
Maj Col
Min Col
Local
;

data B;
    set A;
    functional_num = input(functional,functional.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886865#M350426</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-28T17:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886958#M350466</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; You are right about keeping the initial meaning names e.g local, minor collector etc. It is more meaningful. So I want to have the functional road class in this order:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Interstate&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Freeway&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Pri Art&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Min Art&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Maj Col&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Min Col&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Local.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;So when I run a proc freq, I want it to be in this order. How do I do that ? Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 12:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886958#M350466</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-07-29T12:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886960#M350468</link>
      <description>&lt;P&gt;PROC FREQ has an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_freq_syntax01.htm#statug.freq.freqorder" target="_self"&gt;ORDER= option&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If one of those doesn't work for you, then I would create the numeric value using the INFORMAT as I showed earlier, sort by this numeric value, and then run PROC FREQ on your character variable named FUNCTIONAL (not the numeric variable named FUNCTIONAL_NUM), using the ORDER=DATA option. The sorting causes Interstate to appear first, Freeway will appear second, and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Side comment: ask the real question in your first post, in this case the real question is how to get PROC FREQ to put categories in a specific order; don't ask an indirect question about how to assign numbers to character string categories. Your original question is the &lt;A href="https://en.wikipedia.org/wiki/XY_problem" target="_self"&gt;XY Problem&lt;/A&gt;, and should be avoided.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 13:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886960#M350468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-29T13:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886964#M350471</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thanks for the advice. Well my main goal hasn't been achieved yet. My goal is to change the order of functional in my dataset so that when I run a logistic model or an emperical logit plot I will get the result in the order I want. So I initially thought of changing the variable to numeric and then running the model on the numeric version. However, I wanted the variables in their original names just as you suggested.&lt;/P&gt;&lt;P&gt;The freq is just for me to check if the order changed. The method you proposed in your latest post did change the order in the numeric but it didn't change it in the logistic model. Also, I have other variables in my model so functional is not the only one.&amp;nbsp; Looking forward to your response. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In summary this is what I have in my dataset, in this order but this is what I want in my dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What&amp;nbsp; I have in the dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;FUNCTIONAL:&lt;/P&gt;&lt;P&gt;Freeway&lt;/P&gt;&lt;P&gt;Interst&lt;/P&gt;&lt;P&gt;Local&lt;/P&gt;&lt;P&gt;Maj Col&lt;/P&gt;&lt;P&gt;Min Art&lt;/P&gt;&lt;P&gt;Min Col&lt;/P&gt;&lt;P&gt;Pri Art&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want in my dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;FUNCTIONAL&lt;/P&gt;&lt;P&gt;Interst&lt;/P&gt;&lt;P&gt;Freeway&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pri Art&lt;/P&gt;&lt;P&gt;Min Art&lt;/P&gt;&lt;P&gt;Maj Col&lt;/P&gt;&lt;P&gt;Min Col&lt;/P&gt;&lt;P&gt;Local&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 14:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886964#M350471</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-07-29T14:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886966#M350472</link>
      <description>&lt;P&gt;So that is a different question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does the order the data sorts impact the result of the logistic regression?&amp;nbsp; The only thing I can think of is that it could change which value it considers as the comparison group.&amp;nbsp; Can't you just specify which value to use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What procedure are you using to run logistic regression?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 15:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886966#M350472</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-29T15:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886969#M350473</link>
      <description>&lt;P&gt;When you run a logistic regression, you can specify which level of a variable is the control. In addition, PROC LOGISTIC has the same ORDER= option that PROC FREQ has.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 16:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/886969#M350473</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-29T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921662#M362951</link>
      <description>&lt;P&gt;Is there a way to achieve this by not using the input function?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 06:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921662#M362951</guid>
      <dc:creator>Schalk_Burger</dc:creator>
      <dc:date>2024-03-25T06:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921665#M362952</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/403793"&gt;@Schalk_Burger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to achieve this by not using the input function?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should start your own thread an mention this one as related.&lt;/P&gt;
&lt;P&gt;Likely a number of choices available:&lt;/P&gt;
&lt;P&gt;In a data step use a bunch of If/then/else statements to assign values conditionally. Or Select/when.&lt;/P&gt;
&lt;P&gt;Or use a custom informat when reading the data in the first place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actual example of values you have and the desired numeric values, and perhaps a description of why you need the numeric values, may get a more concrete answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 07:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921665#M362952</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-25T07:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921691#M362955</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. Will do. Not that important, but will start a new thread.</description>
      <pubDate>Mon, 25 Mar 2024 11:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric/m-p/921691#M362955</guid>
      <dc:creator>Schalk_Burger</dc:creator>
      <dc:date>2024-03-25T11:34:41Z</dc:date>
    </item>
  </channel>
</rss>

