<?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: USING TWO DIFFERENT CONDITIONS IN 1 PROC SQL STEP in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526737#M5159</link>
    <description>&lt;P&gt;Your syntax looks really strange (what&amp;nbsp;languages uses&amp;nbsp;"RETURN X IF Y" syntax?) and also the logic of your formula&amp;nbsp;seems off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS it is simple because logical expressions evaluate to 0 or 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select sum( return=0 ) as n_zero
     , count(*) as n 
     , calculated n_zero / calculated n as percent_zero
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other flavors of SQL you will want to use a CASE statement.&amp;nbsp; Also since other languages do not have the CALCULATED keyword you might need to replicate the formulas or use a nested query to get both the count and the percentage in one query.&lt;/P&gt;</description>
    <pubDate>Sun, 13 Jan 2019 16:20:22 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-01-13T16:20:22Z</dc:date>
    <item>
      <title>USING TWO DIFFERENT CONDITIONS IN 1 PROC SQL STEP</title>
      <link>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526717#M5148</link>
      <description>&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select count (return if return= 0) as zero_obs, zero_obs/count (return if return ne 0) as zero_perc from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not getting it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 08:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526717#M5148</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-13T08:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: USING TWO DIFFERENT CONDITIONS IN 1 PROC SQL STEP</title>
      <link>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526719#M5149</link>
      <description>&lt;P&gt;Instead om count(), use sum. In the expression use CASE, it's the SQL counterpart to IF.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(case return when 0 then 1 else 0 end)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 08:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526719#M5149</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2019-01-13T08:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: USING TWO DIFFERENT CONDITIONS IN 1 PROC SQL STEP</title>
      <link>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526737#M5159</link>
      <description>&lt;P&gt;Your syntax looks really strange (what&amp;nbsp;languages uses&amp;nbsp;"RETURN X IF Y" syntax?) and also the logic of your formula&amp;nbsp;seems off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS it is simple because logical expressions evaluate to 0 or 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select sum( return=0 ) as n_zero
     , count(*) as n 
     , calculated n_zero / calculated n as percent_zero
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other flavors of SQL you will want to use a CASE statement.&amp;nbsp; Also since other languages do not have the CALCULATED keyword you might need to replicate the formulas or use a nested query to get both the count and the percentage in one query.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 16:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/USING-TWO-DIFFERENT-CONDITIONS-IN-1-PROC-SQL-STEP/m-p/526737#M5159</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-13T16:20:22Z</dc:date>
    </item>
  </channel>
</rss>

