<?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 Proc sql count for multiple variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684968#M79544</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to be able to count the number of individuals within a state that have a certain option. I know how to do this in proc sql for a single option, but not sure how to construct this if I want counts by states for multiple (i.e., 5) options. I could merge 5 separate proc sql, but I'm wondering if there's a way to do this in a single step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's sample SAS code for the dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id state option1 option2 option3 option4 option5;
cards;
1 1 1 0 1 1 1
2 2 0 0 1 1 1
3 3 0 1 0 1 0
4 1 1 1 0 1 1
5 2 0 1 1 0 1
6 3 1 1 1 1 1
7 1 1 0 0 0 1
8 2 0 1 0 1 0
9 3 1 1 1 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is the dataset that I'm trying to obtain. Note that the counts of individuals are by each state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;state option1 option2 option3 option4 option5&lt;BR /&gt;1 3 1 1 2 3&lt;BR /&gt;2 0 2 2 2 2&lt;BR /&gt;3 2 3 2 3 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any advice that you have!&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2020 13:37:58 GMT</pubDate>
    <dc:creator>luch25</dc:creator>
    <dc:date>2020-09-18T13:37:58Z</dc:date>
    <item>
      <title>Proc sql count for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684968#M79544</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to be able to count the number of individuals within a state that have a certain option. I know how to do this in proc sql for a single option, but not sure how to construct this if I want counts by states for multiple (i.e., 5) options. I could merge 5 separate proc sql, but I'm wondering if there's a way to do this in a single step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's sample SAS code for the dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id state option1 option2 option3 option4 option5;
cards;
1 1 1 0 1 1 1
2 2 0 0 1 1 1
3 3 0 1 0 1 0
4 1 1 1 0 1 1
5 2 0 1 1 0 1
6 3 1 1 1 1 1
7 1 1 0 0 0 1
8 2 0 1 0 1 0
9 3 1 1 1 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is the dataset that I'm trying to obtain. Note that the counts of individuals are by each state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;state option1 option2 option3 option4 option5&lt;BR /&gt;1 3 1 1 2 3&lt;BR /&gt;2 0 2 2 2 2&lt;BR /&gt;3 2 3 2 3 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any advice that you have!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 13:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684968#M79544</guid>
      <dc:creator>luch25</dc:creator>
      <dc:date>2020-09-18T13:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql count for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684969#M79545</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id state option1 option2 option3 option4 option5;
cards;
1 1 1 0 1 1 1
2 2 0 0 1 1 1
3 3 0 1 0 1 0
4 1 1 1 0 1 1
5 2 0 1 1 0 1
6 3 1 1 1 1 1
7 1 1 0 0 0 1
8 2 0 1 0 1 0
9 3 1 1 1 1 1
;

proc summary data=have nway;
 class state;
 var option1-option5;
 output out=want(drop=_:) sum=;
run;

proc print noobs data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 13:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684969#M79545</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-18T13:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql count for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684976#M79546</link>
      <description>&lt;P&gt;Since 0 is a value you apparently do not actually want a Count. If all of the values are 0/1 then use SUM and group by state&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 14:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684976#M79546</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-18T14:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql count for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684984#M79547</link>
      <description>Thank you! This works perfectly. Should have thought of proc summary</description>
      <pubDate>Fri, 18 Sep 2020 14:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-count-for-multiple-variables/m-p/684984#M79547</guid>
      <dc:creator>luch25</dc:creator>
      <dc:date>2020-09-18T14:26:24Z</dc:date>
    </item>
  </channel>
</rss>

