<?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 Calculating counts and percentages with conditions in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702154#M9535</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Could someone help me with the code to solve this problem?&lt;/P&gt;
&lt;P&gt;From data oc below, I would like to select the industry code(indscode) with the following conditions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) In which at least 50% of the jobs are exposed to agent a(0=unexposed, 1=exposed).[I want all percentages to be displayed and from there I will select the &amp;gt;=50%].&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) Couting number of subjects( lung cases(case) and controls(cont) for the selected indscode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used proc SQL, expecting the indscode variable to be displayed on the table results, but it didn't.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coding help is needed to have the indscode&amp;nbsp; count and % displayed on the table,please.&lt;/P&gt;
&lt;P&gt;Please find my code and&amp;nbsp; results below:&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;P&gt;data oc; &lt;BR /&gt;input id$ 1-5 job 6-7 a 8-9 b 10-11 indscode 12-16 lung$ 17-21; &lt;BR /&gt;datalines;&lt;BR /&gt;OS1 3 1 0 6198 case&lt;BR /&gt;OS2 2 1 1 6191 cont&lt;BR /&gt;OS3 3 1 0 6191 case&lt;BR /&gt;OS4 3 0 0 6198 cont&lt;BR /&gt;OS5 3 1 0 6191 case&lt;BR /&gt;OS6 3 1 0 6191 cont&lt;BR /&gt;OS6 4 1 1 6198 case&lt;BR /&gt;OS7 4 1 1 6191 case&lt;BR /&gt;OS8 1 1 1 6191 cont&lt;BR /&gt;OS9 1 0 0 6198 cont&lt;BR /&gt;OS10 1 1 1 6191 cont&lt;BR /&gt;OS11 3 1 1 4153 case&lt;BR /&gt;OS12 1 1 1 6191 case&lt;BR /&gt;OS13 3 1 1 8563 case&lt;BR /&gt;OS14 1 1 1 6191 case&lt;BR /&gt;OS14 2 0 0 6191 cont&lt;BR /&gt;OS14 5 1 1 6191 cont&lt;BR /&gt;OS15 1 1 1 4153 cont&lt;BR /&gt;OS16 1 1 0 8563 case&lt;BR /&gt;OS17 4 1 1 6191 case&lt;BR /&gt;OS17 2 1 0 6191 case&lt;BR /&gt;OS17 3 1 0 6191 cont&lt;BR /&gt;OS20 3 1 1 4153 cont&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select job, count(job)/(select count(*) from oc) as pct format=percent.&lt;BR /&gt;from oc where a=1 /*a=0 is unexposed to agent a; 1= exposed to agent a*/&lt;BR /&gt;group by indscode;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc print data=want;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obs job pct&lt;BR /&gt;1 3 13%&lt;BR /&gt;2 3 13%&lt;BR /&gt;3 1 13%&lt;BR /&gt;4 5 57%&lt;BR /&gt;5 1 57%&lt;BR /&gt;6 3 57%&lt;BR /&gt;7 1 57%&lt;BR /&gt;8 3 57%&lt;BR /&gt;9 1 57%&lt;BR /&gt;10 4 57%&lt;BR /&gt;11 2 57%&lt;BR /&gt;12 4 57%&lt;BR /&gt;13 3 57%&lt;BR /&gt;14 2 57%&lt;BR /&gt;15 3 57%&lt;BR /&gt;16 1 57%&lt;BR /&gt;17 4 9%&lt;BR /&gt;18 3 9%&lt;BR /&gt;19 3 9%&lt;BR /&gt;20 1 9%&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Nov 2020 04:57:14 GMT</pubDate>
    <dc:creator>ak2011</dc:creator>
    <dc:date>2020-11-28T04:57:14Z</dc:date>
    <item>
      <title>Calculating counts and percentages with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702154#M9535</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Could someone help me with the code to solve this problem?&lt;/P&gt;
&lt;P&gt;From data oc below, I would like to select the industry code(indscode) with the following conditions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) In which at least 50% of the jobs are exposed to agent a(0=unexposed, 1=exposed).[I want all percentages to be displayed and from there I will select the &amp;gt;=50%].&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) Couting number of subjects( lung cases(case) and controls(cont) for the selected indscode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used proc SQL, expecting the indscode variable to be displayed on the table results, but it didn't.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coding help is needed to have the indscode&amp;nbsp; count and % displayed on the table,please.&lt;/P&gt;
&lt;P&gt;Please find my code and&amp;nbsp; results below:&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;P&gt;data oc; &lt;BR /&gt;input id$ 1-5 job 6-7 a 8-9 b 10-11 indscode 12-16 lung$ 17-21; &lt;BR /&gt;datalines;&lt;BR /&gt;OS1 3 1 0 6198 case&lt;BR /&gt;OS2 2 1 1 6191 cont&lt;BR /&gt;OS3 3 1 0 6191 case&lt;BR /&gt;OS4 3 0 0 6198 cont&lt;BR /&gt;OS5 3 1 0 6191 case&lt;BR /&gt;OS6 3 1 0 6191 cont&lt;BR /&gt;OS6 4 1 1 6198 case&lt;BR /&gt;OS7 4 1 1 6191 case&lt;BR /&gt;OS8 1 1 1 6191 cont&lt;BR /&gt;OS9 1 0 0 6198 cont&lt;BR /&gt;OS10 1 1 1 6191 cont&lt;BR /&gt;OS11 3 1 1 4153 case&lt;BR /&gt;OS12 1 1 1 6191 case&lt;BR /&gt;OS13 3 1 1 8563 case&lt;BR /&gt;OS14 1 1 1 6191 case&lt;BR /&gt;OS14 2 0 0 6191 cont&lt;BR /&gt;OS14 5 1 1 6191 cont&lt;BR /&gt;OS15 1 1 1 4153 cont&lt;BR /&gt;OS16 1 1 0 8563 case&lt;BR /&gt;OS17 4 1 1 6191 case&lt;BR /&gt;OS17 2 1 0 6191 case&lt;BR /&gt;OS17 3 1 0 6191 cont&lt;BR /&gt;OS20 3 1 1 4153 cont&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select job, count(job)/(select count(*) from oc) as pct format=percent.&lt;BR /&gt;from oc where a=1 /*a=0 is unexposed to agent a; 1= exposed to agent a*/&lt;BR /&gt;group by indscode;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc print data=want;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obs job pct&lt;BR /&gt;1 3 13%&lt;BR /&gt;2 3 13%&lt;BR /&gt;3 1 13%&lt;BR /&gt;4 5 57%&lt;BR /&gt;5 1 57%&lt;BR /&gt;6 3 57%&lt;BR /&gt;7 1 57%&lt;BR /&gt;8 3 57%&lt;BR /&gt;9 1 57%&lt;BR /&gt;10 4 57%&lt;BR /&gt;11 2 57%&lt;BR /&gt;12 4 57%&lt;BR /&gt;13 3 57%&lt;BR /&gt;14 2 57%&lt;BR /&gt;15 3 57%&lt;BR /&gt;16 1 57%&lt;BR /&gt;17 4 9%&lt;BR /&gt;18 3 9%&lt;BR /&gt;19 3 9%&lt;BR /&gt;20 1 9%&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 04:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702154#M9535</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2020-11-28T04:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating counts and percentages with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702161#M9536</link>
      <description>&lt;P&gt;A variable that you want in the result dataset must be part of the SELECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select
  indscode,
  sum(a) / count(*) format=percent7.2 as pct
from oc.
group by indscode&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2020 07:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702161#M9536</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T07:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating counts and percentages with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702168#M9537</link>
      <description>Hi, &lt;BR /&gt;Thanks for your code. However, there are 2 more condition to be met:&lt;BR /&gt;(1)  where a=1(exposed) and I should also know the n's (ie. the counts) that generated that %s.&lt;BR /&gt;(2) Count the number of cases and conts.&lt;BR /&gt;I don't know if proc freq too  can solve this problem.&lt;BR /&gt;ak.</description>
      <pubDate>Sat, 28 Nov 2020 11:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702168#M9537</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2020-11-28T11:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating counts and percentages with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702169#M9538</link>
      <description>&lt;P&gt;Since a is either 1 or 0, sum(a) is an exact count of the 1's.&lt;/P&gt;
&lt;P&gt;sum(lung = "case") and sum(lung = "cont") gives you the respective counts. Keep in mind that the boolean result of a comparison is also either 1 or 0.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 11:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702169#M9538</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T11:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating counts and percentages with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702287#M9540</link>
      <description>Thanks.</description>
      <pubDate>Sun, 29 Nov 2020 11:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Calculating-counts-and-percentages-with-conditions/m-p/702287#M9540</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2020-11-29T11:59:11Z</dc:date>
    </item>
  </channel>
</rss>

