<?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: Counting values in multiple variables to create new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575923#M162962</link>
    <description>&lt;P&gt;Very neat and elegant sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FWIW an ordinary solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data want;
set outcome;
count_1=countc(cats(of outcome:),'1');
count_0=countc(cats(of outcome:),'0');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2019 18:42:52 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-07-23T18:42:52Z</dc:date>
    <item>
      <title>Counting values in multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575919#M162959</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with a data set where I have created new variables based on success of outcomes. 0=not sucessful 1=successful .= outcome not applicable to client.&amp;nbsp; I want to create a 2 new variables count_1 and count_0 that each count the number of 1s and 0s from the outcomes variables so I can eventually calculate a success rate for each client. Thanks in advance for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data outcome;&lt;/P&gt;&lt;P&gt;input client outcome1 outcome2 outcome3;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A . . 0&lt;/P&gt;&lt;P&gt;B . 1 0&lt;/P&gt;&lt;P&gt;C 0 0 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;D . . 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 18:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575919#M162959</guid>
      <dc:creator>JenMMerc</dc:creator>
      <dc:date>2019-07-23T18:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Counting values in multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575920#M162960</link>
      <description>&lt;P&gt;In a datastep&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; count_1= sum( of outcome: );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; count_0 = n(of outcome: ) - count_1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the outcome: with the colon is a variable list of all of the variables, with the data step functions such as sum, mean, n, std etc then&lt;/P&gt;
&lt;P&gt;sum&amp;nbsp;( of outcome:) is the sum of all the non-missing values. Which with 1/0 coded variables is the same as the count of 1.&lt;/P&gt;
&lt;P&gt;The N function returns the number of non-missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;BTW mean(of outcome: ) will the be percent of 1's .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 18:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575920#M162960</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-23T18:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Counting values in multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575923#M162962</link>
      <description>&lt;P&gt;Very neat and elegant sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FWIW an ordinary solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data want;
set outcome;
count_1=countc(cats(of outcome:),'1');
count_0=countc(cats(of outcome:),'0');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 18:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575923#M162962</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-23T18:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting values in multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575926#M162963</link>
      <description>It worked! Thank you.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Jul 2019 18:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575926#M162963</guid>
      <dc:creator>JenMMerc</dc:creator>
      <dc:date>2019-07-23T18:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting values in multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575933#M162967</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213591"&gt;@JenMMerc&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to SAS communities. May i request you to mark BallardW's solution as answered and close the thread. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 18:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-values-in-multiple-variables-to-create-new-variable/m-p/575933#M162967</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-23T18:58:33Z</dc:date>
    </item>
  </channel>
</rss>

