<?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: Better code to caulculae Tamhil_bads Tamhil_goods in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720642#M223246</link>
    <description>Thank you, however in this code there is no calculation of :proportion_good ,proportion_bads.&lt;BR /&gt;</description>
    <pubDate>Sat, 20 Feb 2021 11:54:30 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-02-20T11:54:30Z</dc:date>
    <item>
      <title>Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720635#M223241</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Is there a better way with&amp;nbsp; less code to calculated the following for each team category:&lt;/P&gt;
&lt;P&gt;Number of customers&lt;/P&gt;
&lt;P&gt;Number of bad customers&lt;/P&gt;
&lt;P&gt;Number of good customers&lt;/P&gt;
&lt;P&gt;Percent of bad customers in each category&lt;/P&gt;
&lt;P&gt;proprtion of bad customers from all bad customers&lt;/P&gt;
&lt;P&gt;proprtion of good customers from all good customers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide solution in the following ways:&lt;/P&gt;
&lt;P&gt;1-Proc sql&lt;/P&gt;
&lt;P&gt;2-proc report&lt;/P&gt;
&lt;P&gt;3-proc tabulate&lt;/P&gt;
&lt;P&gt;4-proc summary&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
Input ID Team Ind_Fail;
Cards;
1 a 0
2 a 1
3 b 0
4 b 1
5 a 0
6 b 0
7 a 1
8 a 0
9 b 1
;
Run;
 
Proc sql;
Create table as wanted_a as
Select  Team,
Count(*) as nr_customers,   
Sum(Ind_Fail) as nr_bads,
Sum(calculated  nr_customers,- calculated nr_fails) as Nr_goods ,
Calculated nr_bads/ Calculated nr_customers as PCT_bads
From tbl
Group by Team
;
Quit;





Proc sql;
Create table as wanted_b as
Select  Count(*) as  Total_nr_customers,   
Sum(Ind_Fail) as Total_nr_bads,
Sum(calculated  Total_nr_customers,- calculated Total_nr_fails) as Total_Nr_goods 
From tbl
Group by Team
;
Quit;

Data  wanted_c;
Merge wanted_a (in=a) wanted_b(in=b);
proportion_good=Nr_goods/Total_Nr_goods;
proportion_bads=nr_bads/ Total_Nr_bads;
Format proportion_good proportion_bads comma8.2;
Run;



 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2021 11:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720635#M223241</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-02-20T11:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720637#M223243</link>
      <description>&lt;P&gt;Compare your first sql to next fixed code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
Input ID Team $ Ind_Fail;
Cards;
1 a 0
2 a 1
3 b 0
4 b 1
5 a 0
6 b 0
7 a 1
8 a 0
9 b 1
;
Run;
 
Proc sql;
	Create table wanted_a as
	Select  Team,
	Count(*) as nr_customers,   
	Sum(Ind_Fail) as nr_bads,
	Sum(calculated  nr_customers,- calculated nr_bads) as Nr_goods ,
	Calculated nr_bads/ Calculated nr_customers as PCT_bads
	From tbl
	Group by Team
;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2021 11:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720637#M223243</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-20T11:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720642#M223246</link>
      <description>Thank you, however in this code there is no calculation of :proportion_good ,proportion_bads.&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Feb 2021 11:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720642#M223246</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-02-20T11:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720649#M223249</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
Input ID Team $ Ind_Fail;
Cards;
1 a 0
2 a 1
3 b 0
4 b 1
5 a 0
6 b 0
7 a 1
8 a 0
9 b 1
;
Run;
proc sql;
create table want as
 select Team,
count(*) as n ,
calculated n/(select count(*) from tbl) as percent format=percent7.2 ,
sum(Ind_Fail=1) as n_bad ,
sum(Ind_Fail=0) as n_good ,
sum(Ind_Fail=1)/(select sum(Ind_Fail=1) from tbl ) as bad_percent,
sum(Ind_Fail=0)/(select sum(Ind_Fail=0) from tbl ) as good_percent,
log(calculated bad_percent/calculated good_percent) as woe
from tbl
   group by Team;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2021 12:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720649#M223249</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-20T12:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720656#M223253</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, however in this code there is no calculation of :proportion_good ,proportion_bads.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have added the required:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
	Create table wanted_a as
	Select  Team,
	Count(*) as nr_customers,   
	Sum(Ind_Fail) as nr_bads,
	Sum(calculated  nr_customers,- calculated nr_bads) as Nr_goods ,
	Calculated nr_bads/ Calculated nr_customers as PCT_bads format percent5.2
	From tbl
	Group by Team
   ;
   create table wanted_b as 
   select sum(nr_bads) / sum(nr_customers) as proportion_bads format 4.3,
          1- calculated proportion_bads as proportion_good  format 4.3
   from wanted_a
  ;
   create table want_c as 
   select a.*, b.*
   from wanted_a as a , wanted_b as b 
  ;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2021 15:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720656#M223253</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-20T15:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720658#M223254</link>
      <description>sum(nr_bads) / sum(nr_customers) as proportion_bads&lt;BR /&gt;  is not correct because  need to calculate number of bads in each category divided by total number of bads....&lt;BR /&gt;Maybe this solution will work well? But still using here 3 proc sql so didnt save code....&lt;BR /&gt;&lt;BR /&gt;Proc sql;&lt;BR /&gt;	Create table wanted_a as&lt;BR /&gt;	Select  Team,&lt;BR /&gt;	Count(*) as nr_customers,   &lt;BR /&gt;	Sum(Ind_Fail) as nr_bads,&lt;BR /&gt;	Sum(calculated  nr_customers,- calculated nr_bads) as Nr_goods ,&lt;BR /&gt;	Calculated nr_bads/ Calculated nr_customers as PCT_bads format percent5.2&lt;BR /&gt;	From tbl&lt;BR /&gt;	Group by Team&lt;BR /&gt;   ;&lt;BR /&gt;   create table wanted_b as &lt;BR /&gt;   select   nr_bads/ sum(nr_bads) as proportion_bads format 4.3,&lt;BR /&gt;              Nr_goods /sum(Nr_goods ) as  proportion_goods format 4.3&lt;BR /&gt;   from wanted_a&lt;BR /&gt;  ;&lt;BR /&gt;   create table want_c as &lt;BR /&gt;   select a.*, b.*&lt;BR /&gt;   from wanted_a as a , wanted_b as b &lt;BR /&gt;  ;&lt;BR /&gt;Quit;&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Feb 2021 18:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720658#M223254</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-02-20T18:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Better code to caulculae Tamhil_bads Tamhil_goods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720659#M223255</link>
      <description>May anyone show ways to do it with proc report/proc tabulate?</description>
      <pubDate>Sat, 20 Feb 2021 18:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Better-code-to-caulculae-Tamhil-bads-Tamhil-goods/m-p/720659#M223255</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-02-20T18:54:17Z</dc:date>
    </item>
  </channel>
</rss>

