<?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: proc sql using where clause in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498889#M72544</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159458"&gt;@HN2001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm doing other calculations besides frequencies so I was experimenting with sql to do my freqs and averages in one data step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can do some of that with weights statement, not sure about the average portion though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do it in SQL but it is essentially hard coding in your rules and values so if something changes your code needs to change.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Sep 2018 22:31:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-09-25T22:31:38Z</dc:date>
    <item>
      <title>proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498867#M72536</link>
      <description>&lt;P&gt;I'm trying to use where in the select statement of sql but it isn't working properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data like the following&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Final_Decision&lt;/TD&gt;&lt;TD&gt;Item Type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Keep&lt;/TD&gt;&lt;TD&gt;Type1&lt;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;TD&gt;Type1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a table like this&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Item Type&lt;/TD&gt;&lt;TD&gt;Total Items&lt;/TD&gt;&lt;TD&gt;Number not excluded&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Type1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Type2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&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 have the following sas code but the second select statement is calculating the whole number not excluded for each item type&lt;/P&gt;&lt;P&gt;any suggestions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table typ_out as&lt;BR /&gt;select Item_Type, Count(Item_Type) as N_total, (select Count(Item_Type) from both where Final_Decision ne "Exclude") as N_remain&lt;BR /&gt;from Both&lt;BR /&gt;group by Item_Type;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 21:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498867#M72536</guid>
      <dc:creator>HN2001</dc:creator>
      <dc:date>2018-09-25T21:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498871#M72537</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Final_Decision $	ItemType $;
cards;
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type2
Exclude	Type2
Keep	Type2
Keep	Type1
Exclude	Type1
Keep	Type2
Exclude	Type2
Keep	Type2
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type1
;



proc sql;
create table want as
select ItemType,count(ItemType) as c,sum(Final_Decision='Keep') as c1
from have
group by ItemType;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 21:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498871#M72537</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-25T21:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498876#M72538</link>
      <description>Your suggestion works well but is there any reason why the count statement wouldn't work?&lt;BR /&gt;&lt;BR /&gt;Additionally, if I had another column of data as times&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards truncover;&lt;BR /&gt;input Final_Decision $ ItemType $ Time;&lt;BR /&gt;cards;&lt;BR /&gt;Keep Type1 2&lt;BR /&gt;Keep Type1 3&lt;BR /&gt;Keep Type1 2&lt;BR /&gt;Keep Type2 4&lt;BR /&gt;Exclude Type2 9&lt;BR /&gt;Keep Type2 3&lt;BR /&gt;Keep Type1 2&lt;BR /&gt;Exclude Type1 11&lt;BR /&gt;Keep Type2 1&lt;BR /&gt;Exclude Type2 10&lt;BR /&gt;Keep Type2 2&lt;BR /&gt;Keep Type1 3&lt;BR /&gt;Keep Type1 3&lt;BR /&gt;Keep Type1 4&lt;BR /&gt;Keep Type1 5&lt;BR /&gt;Keep Type1 3&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;I also tried the where statement again since I can't do avg(time where Final_Decision ne 'Exclude'). Can you offer help on that as well?&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Sep 2018 21:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498876#M72538</guid>
      <dc:creator>HN2001</dc:creator>
      <dc:date>2018-09-25T21:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498877#M72539</link>
      <description>&lt;P&gt;See if this is what you want for the new sample with time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Final_Decision $ ItemType $ Time;
cards;
Keep Type1 2
Keep Type1 3
Keep Type1 2
Keep Type2 4
Exclude Type2 9
Keep Type2 3
Keep Type1 2
Exclude Type1 11
Keep Type2 1
Exclude Type2 10
Keep Type2 2
Keep Type1 3
Keep Type1 3
Keep Type1 4
Keep Type1 5
Keep Type1 3
;


proc sql;
create table want as
select ItemType,count(ItemType) as c,sum(Final_Decision='Keep') as c1, mean(ifn(Final_Decision='Keep',1,.)*time) as avg
from have
group by ItemType;
quit;&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, 25 Sep 2018 22:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498877#M72539</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-25T22:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498881#M72540</link>
      <description>Any reason you're not just using PROC FREQ here?</description>
      <pubDate>Tue, 25 Sep 2018 22:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498881#M72540</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-25T22:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498882#M72541</link>
      <description>&lt;P&gt;I'm doing other calculations besides frequencies so I was experimenting with sql to do my freqs and averages in one data step.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 22:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498882#M72541</guid>
      <dc:creator>HN2001</dc:creator>
      <dc:date>2018-09-25T22:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498884#M72542</link>
      <description>&lt;P&gt;yes that is what I am looking for.&amp;nbsp; Thanks for giving me an alternative to getting those calculations.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 22:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498884#M72542</guid>
      <dc:creator>HN2001</dc:creator>
      <dc:date>2018-09-25T22:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498885#M72543</link>
      <description>&lt;P&gt;Most Welcome. Have a good one!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 22:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498885#M72543</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-25T22:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498889#M72544</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159458"&gt;@HN2001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm doing other calculations besides frequencies so I was experimenting with sql to do my freqs and averages in one data step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can do some of that with weights statement, not sure about the average portion though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do it in SQL but it is essentially hard coding in your rules and values so if something changes your code needs to change.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 22:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498889#M72544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-25T22:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498939#M72546</link>
      <description>&lt;P&gt;If you want to use a subquery, it must be correlated with the main query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Final_Decision $	ItemType $;
cards;
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type2
Exclude	Type2
Keep	Type2
Keep	Type1
Exclude	Type1
Keep	Type2
Exclude	Type2
Keep	Type2
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type1
Keep	Type1
;

proc sql;
create table typ_out as
select 
    ItemType, 
    Count(*) as N_total, 
    (select Count(*) from have 
        where Final_Decision ne "Exclude" and itemtype = a.itemtype) as N_remain
from have as a
group by ItemType;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 03:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/498939#M72546</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-26T03:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using where clause</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/499074#M72548</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Final_Decision $ ItemType $ Time;
cards;
Keep Type1 2
Keep Type1 3
Keep Type1 2
Keep Type2 4
Exclude Type2 9
Keep Type2 3
Keep Type1 2
Exclude Type1 11
Keep Type2 1
Exclude Type2 10
Keep Type2 2
Keep Type1 3
Keep Type1 3
Keep Type1 4
Keep Type1 5
Keep Type1 3
;


proc sql;
create table want as
select ItemType,count(ItemType) as totalitems,
sum(Final_Decision ne 'Exclude') as number_not_excluded
from have
group by ItemType;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 13:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-where-clause/m-p/499074#M72548</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-26T13:29:29Z</dc:date>
    </item>
  </channel>
</rss>

