<?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: Sum function and ignoring characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824689#M325690</link>
    <description>&lt;P&gt;Make a NUMERIC variable.&amp;nbsp; Now you can do any arithmetic you want with the variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need to define a special INFORMAT. Use the MISSING statement to tell SAS which single letter text strings to interpret as representing the corresponding special missing numeric values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;missing M Z ;
data have;
  input var ;
cards;
1
0
2
M
Z
;
proc print;
run;
proc means n min max mean;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1658415932908.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73580iAA6EE9EA528DB4AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1658415932908.png" alt="Tom_0-1658415932908.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jul 2022 15:11:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-21T15:11:42Z</dc:date>
    <item>
      <title>Sum function and ignoring characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824494#M325612</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am trying to sum some variables which have scores 0-1-2 and characters 'Z' or 'M'. I want to sum numbers and ignore those character responses. Any ideas how i can do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 20:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824494#M325612</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-07-20T20:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sum function and ignoring characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824498#M325613</link>
      <description>&lt;P&gt;Convert the variables to numeric; use the special missing values .M and .Z for the characters.&lt;/P&gt;
&lt;P&gt;The SUM function will then work correctly, as will procedures like MEANS.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 20:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824498#M325613</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-20T20:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum function and ignoring characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824569#M325646</link>
      <description>&lt;P&gt;You can also create in informat and use that in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;&lt;BR /&gt;input ID score $;&lt;BR /&gt;cards;&lt;BR /&gt;1 1&lt;BR /&gt;1 3&lt;BR /&gt;1 M&lt;BR /&gt;2 Z&lt;BR /&gt;2 2&lt;BR /&gt;2 2&lt;BR /&gt;2 3&lt;BR /&gt;;run;&lt;BR /&gt;&lt;BR /&gt;proc format;
  invalue score
  '1'=1
  '2'=2
  '3'=3
  'M'=.M
  'Z'=.Z&lt;BR /&gt;  other=_ERROR_
  ;
run;

proc sql;
  create table want as
  select id,sum(input(score,score.)) as score
  from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, you could also use the informat when reading the data in the first place, you can then use PROC SUMMARY etc. on the score variable, which is now numeric:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID score score.;
cards;
1 1
1 3
1 M
2 Z
2 2
2 2
2 3
;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 09:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824569#M325646</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-07-21T09:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum function and ignoring characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824689#M325690</link>
      <description>&lt;P&gt;Make a NUMERIC variable.&amp;nbsp; Now you can do any arithmetic you want with the variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need to define a special INFORMAT. Use the MISSING statement to tell SAS which single letter text strings to interpret as representing the corresponding special missing numeric values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;missing M Z ;
data have;
  input var ;
cards;
1
0
2
M
Z
;
proc print;
run;
proc means n min max mean;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1658415932908.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73580iAA6EE9EA528DB4AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1658415932908.png" alt="Tom_0-1658415932908.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 15:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-function-and-ignoring-characters/m-p/824689#M325690</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-21T15:11:42Z</dc:date>
    </item>
  </channel>
</rss>

