<?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: How to sum up the valid responses from some variables ignore the missing values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631105#M18912</link>
    <description>&lt;P&gt;You could explcitly group the names into an array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Fruits is the name of the array*/

array fruits&amp;nbsp;&amp;nbsp;orange apple pear&amp;nbsp; kiwi;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 21:12:53 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-03-10T21:12:53Z</dc:date>
    <item>
      <title>How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631060#M18907</link>
      <description>&lt;P&gt;Hi SAS Pros,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am have a data like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 288pt;" border="0" width="384" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var3&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var4&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var5&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to&amp;nbsp;sum up the valid responses from these variables and ignore the missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 336pt;" border="0" width="448" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var3&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var4&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var5&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Var6&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for any help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 18:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631060#M18907</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2020-03-10T18:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631062#M18908</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Var1	Var2	Var3	Var4	Var5	Var6;
cards;
1	2	0	.	.	.
0	.	1	1	1	1
2	0	.	.	2	2
1	2	1	1	2	4
;

data want;
 set have;
 total=sum(of var1-var6);
run;
/*Or explicitly define in an array*/
data want;
 set have;
 array v var1 var2 var3 var4 var5 var6;
 total=sum(of v(*));
run;
/*Or with a double dash if the number suffix is not consecutive
but the arrangement is consecutive*/
data want;
 set have;
 array v var1--var6;
 total=sum(of v(*));
run;
/*Or a double dash without array grouping if the /
arrangement of variables is consecutive*/
data want;
 set have;
 total=sum(of  var1--var6);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 18:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631062#M18908</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T18:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631098#M18909</link>
      <description>&lt;P&gt;Thank you so much for you prompt reply!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if all the missing in the Have data set is replaced by some negative values, i.e. -1, -3, -4. The negative values represent different reasons for missing. It just those negative values are the initial responses available in my data set, and I want to treat them as missing. Can I still use the sum (of ) code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631098#M18909</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2020-03-10T20:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631100#M18910</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266374"&gt;@CynthiaWei&lt;/a&gt;&amp;nbsp; You could reset the negative values to missing and then sum like-&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 array v var1--var6; 
 do over v;
  if v&amp;lt;0 then v=.;
 end;
 total=sum(of  var1--var6);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631100#M18910</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T20:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631101#M18911</link>
      <description>&lt;P&gt;Thank you for the code. But in my actual data set the variables are not array, the names are like orange, apple, pear, and kiwi. What the code should be like if this is the case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 21:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631101#M18911</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2020-03-10T21:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631105#M18912</link>
      <description>&lt;P&gt;You could explcitly group the names into an array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Fruits is the name of the array*/

array fruits&amp;nbsp;&amp;nbsp;orange apple pear&amp;nbsp; kiwi;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 21:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631105#M18912</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T21:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum up the valid responses from some variables ignore the missing values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631117#M18913</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266374"&gt;@CynthiaWei&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for you prompt reply!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if all the missing in the Have data set is replaced by some negative values, i.e. -1, -3, -4. The negative values represent different reasons for missing. It just those negative values are the initial responses available in my data set, and I want to treat them as missing. Can I still use the sum (of ) code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless you have more than 27 codes you should replace the -1, -3, -4 with SAS special missing values. These are .A to .Z and ._ (note the preceding dot just like normal missing).&lt;/P&gt;
&lt;P&gt;You can assign a format to display the meaning of the special missing but for calculations and modeling the missing will be excluded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can even read the into special missing if reading the data with a data step.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
invalue mymiss 
'-1' = .A
'-2' = .B
'-3' = .C
other = [best8.]
;
value mymiss
.A = 'Not Recorded'
.B = 'Refused to Answer'
.C = 'Score out of Range'
;
run;

data example;
   informat var1 - var3 mymiss. ;
   input var1 - var3;
   total = sum(of var:);
datalines;
1 2 3
4 -1 6
5 4 -2
-3 -2 -1
;

proc print data=example;
   format var1 - var3 mymiss.;
run;

&lt;/PRE&gt;
&lt;P&gt;With existing data you would use a data step and code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var1= -1 then var1= .A;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the value can be .a or .A but will appear in table views as the upper case letter as they will in Proc Print output without a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run the data through proc freq without the&amp;nbsp; MISSING option on the tables statement then the missing values do not appear. If you use MISSING without a format then the special missing character appears. If you use a format with missing then you get the formatted value.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 21:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-up-the-valid-responses-from-some-variables-ignore-the/m-p/631117#M18913</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-10T21:55:48Z</dc:date>
    </item>
  </channel>
</rss>

