<?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: Combine PROC SQL code blocks that have different where statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678681#M204862</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18062"&gt;@gzr2mz39&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;that's what I'm looking for.&lt;/P&gt;
&lt;P&gt;But if I want to sum "x" then shouldn't it be like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE contractors_date_range_a AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;sum(case when doi between '01Aug2020'd and today() then x else 0 end) as ee_quarter_count&lt;BR /&gt;from company_data&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. If you wanted change the program to generate the sum of X instead of just counting the number of non-misisng values of X.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note if you did still want the count then you might use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count(case when (doi between '01Aug2020'd and today()) then x else null end)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Aug 2020 17:50:00 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-08-22T17:50:00Z</dc:date>
    <item>
      <title>Combine PROC SQL code blocks that have different where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678607#M204835</link>
      <description>&lt;P&gt;Is there a way to combine these 3 PROC SQL code blocks into 1 PROC SQL code block? The only 2 parts of the SQL code that change are the name of the count(x) variable and the date range used in the where statement.&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE comp_date_range AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;count(x) as ee_quarter20_count&lt;BR /&gt;from company_data&lt;BR /&gt;where doi between '01Aug2020'd and today()&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE comp_date_range1 AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;count(x) as ee_quarter19_count&lt;BR /&gt;from company_data&lt;BR /&gt;where doi between '01Aug2019'd and intnx('year',today(),-1,'same')&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE comp_date_range2 AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;count(x) as ee_ytd_count&lt;BR /&gt;from company_data&lt;BR /&gt;where doi between '01Jan2020'd and today()&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 23:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678607#M204835</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2020-08-21T23:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PROC SQL code blocks that have different where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678613#M204836</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select company
     , sum(doi between '01Aug2020'd and today()) as ee_quarter20_count
     , sum(doi between '01Aug2019'd and today()) as ee_quarter19_count
from company_data;
group by company;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 00:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678613#M204836</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-08-22T00:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PROC SQL code blocks that have different where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678620#M204837</link>
      <description>&lt;P&gt;Yes, thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;that's what I'm looking for.&lt;/P&gt;&lt;P&gt;But if I want to sum "x" then shouldn't it be like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE contractors_date_range_a AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;sum(case when doi between '01Aug2020'd and today() then x else 0 end) as ee_quarter_count&lt;BR /&gt;from company_data&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 01:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678620#M204837</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2020-08-22T01:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PROC SQL code blocks that have different where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678631#M204839</link>
      <description>&lt;P&gt;You could define the summarizing periods in a separate dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data periods;
startDate =  '01Aug2020'd; endDate = today(); period = "Qtr 20"; output;
startDate =  '01Aug2019'd; endDate = intnx('year',today(),-1,'same'); period = "Qtr 19"; output;
startDate =  '01Jan2020'd; endDate = today(); period = "Ytd"; output;
run;

proc sql;
create table comp_date as
select
	period,
	company,
	count(x) as count_x
from
	periods, company_data
where doi between startDate and endDate
group by period, company;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Aug 2020 03:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678631#M204839</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-08-22T03:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PROC SQL code blocks that have different where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678681#M204862</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18062"&gt;@gzr2mz39&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;that's what I'm looking for.&lt;/P&gt;
&lt;P&gt;But if I want to sum "x" then shouldn't it be like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE contractors_date_range_a AS&lt;BR /&gt;SELECT company,&lt;BR /&gt;sum(case when doi between '01Aug2020'd and today() then x else 0 end) as ee_quarter_count&lt;BR /&gt;from company_data&lt;BR /&gt;group by company&lt;BR /&gt;;&lt;BR /&gt;run;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. If you wanted change the program to generate the sum of X instead of just counting the number of non-misisng values of X.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note if you did still want the count then you might use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count(case when (doi between '01Aug2020'd and today()) then x else null end)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Aug 2020 17:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-PROC-SQL-code-blocks-that-have-different-where/m-p/678681#M204862</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-22T17:50:00Z</dc:date>
    </item>
  </channel>
</rss>

