<?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 format from Character to Numeric in PROC MEANS step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730448#M227455</link>
    <description>&lt;P&gt;You could do it in a view? A view is only run when you reference it so it's somewhat like having it done in the proc means step. Depending on what you're calculating you could also use SQL.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp/view=temp;
set have;
distance_num = input(distance, best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;In general though, I find it's worth the time to ensure my data is correctly read in and set up before I start doing any analysis. From a programming stand point its:&lt;BR /&gt;&lt;BR /&gt;1. Import data&lt;BR /&gt;2. Clean&lt;BR /&gt;3. Explore&lt;BR /&gt;4. Analysis&lt;BR /&gt;5. Report&lt;BR /&gt;&lt;BR /&gt;If during stage 3-5 I find a data issue such as this, I'll actually go back to Step 2 to fix it to ensure it flows through the rest of my programs and I'm not dealing with the same issue multiple times over. &lt;BR /&gt;&lt;BR /&gt;SQL option:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select class, mean(input(age, 8.)) as avg_age
from have
group by class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 31 Mar 2021 19:05:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-31T19:05:10Z</dc:date>
    <item>
      <title>Convert format from Character to Numeric in PROC MEANS step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730441#M227449</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if there is any way to convert the format of input variable in proc means from character to numeric without actually having to create the variable in the data-set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This syntax won't work, but I want something like this:&lt;/P&gt;&lt;P&gt;PROC MEANS DATA=Cars;&lt;/P&gt;&lt;P&gt;var input(distance,best.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 17:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730441#M227449</guid>
      <dc:creator>sam_sas2</dc:creator>
      <dc:date>2021-03-31T17:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert format from Character to Numeric in PROC MEANS step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730444#M227451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327668"&gt;@sam_sas2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there is any way to convert the format of input variable in proc means from character to numeric without actually having to create the variable in the data-set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This syntax won't work, but I want something like this:&lt;/P&gt;
&lt;P&gt;PROC MEANS DATA=Cars;&lt;/P&gt;
&lt;P&gt;var input(distance,best.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to create the proper numeric variables in a DATA step before you run PROC MEANS.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 17:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730444#M227451</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-31T17:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert format from Character to Numeric in PROC MEANS step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730445#M227452</link>
      <description>&lt;P&gt;That's a bummer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping if we could create a user defined function and call it?&lt;BR /&gt;I don't know. I'm relatively new to SAS so..&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 17:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730445#M227452</guid>
      <dc:creator>sam_sas2</dc:creator>
      <dc:date>2021-03-31T17:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert format from Character to Numeric in PROC MEANS step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730448#M227455</link>
      <description>&lt;P&gt;You could do it in a view? A view is only run when you reference it so it's somewhat like having it done in the proc means step. Depending on what you're calculating you could also use SQL.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp/view=temp;
set have;
distance_num = input(distance, best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;In general though, I find it's worth the time to ensure my data is correctly read in and set up before I start doing any analysis. From a programming stand point its:&lt;BR /&gt;&lt;BR /&gt;1. Import data&lt;BR /&gt;2. Clean&lt;BR /&gt;3. Explore&lt;BR /&gt;4. Analysis&lt;BR /&gt;5. Report&lt;BR /&gt;&lt;BR /&gt;If during stage 3-5 I find a data issue such as this, I'll actually go back to Step 2 to fix it to ensure it flows through the rest of my programs and I'm not dealing with the same issue multiple times over. &lt;BR /&gt;&lt;BR /&gt;SQL option:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select class, mean(input(age, 8.)) as avg_age
from have
group by class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Mar 2021 19:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730448#M227455</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-31T19:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert format from Character to Numeric in PROC MEANS step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730449#M227456</link>
      <description>&lt;P&gt;It may help to provide an example of what your are attempting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say Format and variable type, numeric or character, then you are saying the type of variable the format is applied to, not a result.&lt;/P&gt;
&lt;P&gt;You can display any text for a given range of numeric values. Common: 1='Yes' 0='No'&lt;/P&gt;
&lt;P&gt;or you can display Digits from a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc format;
value agerange
1-14 = '1 to 14'
15-high='15 plus'
;
run;

proc means data=sashelp.class;
   class age;
   format age agerange.;
   var height weight;
run;&lt;/PRE&gt;
&lt;P&gt;You have to associate the format with a variable. Since the calculated statistics above don't have a "variable" per se those are unlikely candidates for any custom formats at this stage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A more concrete example with data and the type of output you want would be helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 17:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-format-from-Character-to-Numeric-in-PROC-MEANS-step/m-p/730449#M227456</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-31T17:53:43Z</dc:date>
    </item>
  </channel>
</rss>

