<?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 help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443186#M110857</link>
    <description>&lt;P&gt;Please supply some example data in a data step so we can test code against it.&lt;/P&gt;
&lt;P&gt;Try a having clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output as
select *
from input t
group by t.person, t.date
having max(t.readmission_claim) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Mar 2018 07:01:59 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-07T07:01:59Z</dc:date>
    <item>
      <title>Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443185#M110856</link>
      <description>&lt;P&gt;Hi SAS community...&lt;/P&gt;&lt;P&gt;Long time lurker but new user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I have a question that I am stumped with.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have 1 data set with all my data. There are multiple rows with each user and each user may have multiple dates. For example, there can be multiple rows for the same person on the same date and then additional rows for more dates and so on...&lt;/LI&gt;&lt;LI&gt;Now, I want to delete dates where the claim is 0 and keep those dates where the claim is 1. So, all claims on that date where the claim exists will be kept and all dates where claim is 0 will be removed. For example, the claim is readmission. So, for example, for one date, the person may have 5 claims but one claim=1 so I want to keep all those claims on that date.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I created a separate variable 'readmission_claim=1' if the claim was readmission. The other claims are all 0.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;t is my data set&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;Here is code I have but it's not removing dates that have 0&amp;nbsp;claim.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output as select * from input t
where exists (select * from input t where t.person=t.person and t.date=t.date and t.readmission_claim=1); 
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 06:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443185#M110856</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2018-03-07T06:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443186#M110857</link>
      <description>&lt;P&gt;Please supply some example data in a data step so we can test code against it.&lt;/P&gt;
&lt;P&gt;Try a having clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output as
select *
from input t
group by t.person, t.date
having max(t.readmission_claim) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 07:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443186#M110857</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-07T07:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443196#M110860</link>
      <description>&lt;P&gt;The problem seems to be that you are using the same alias inside and outside your EXISTS subquery. Try removing the t alias from the inner query table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output as select * from input t
where exists (select * from input where person=t.person and date=t.date and readmission_claim=1); 
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In your original query, all rows will be included if there is a single row in the whole table having readmission_claim=1, otherwise no rows will be selected.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 07:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443196#M110860</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-07T07:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443197#M110861</link>
      <description>&lt;P&gt;So I made up some quick-and-dirty test data, and ran my SQL against it. See the result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
input person date :yymmdd8. readmission_claim;
format date yymmddd10.;
cards;
1 20180305 0
1 20180305 1
1 20180306 0
1 20180306 0
2 20180305 0
2 20180305 0
2 20180306 0
2 20180306 0
;
run;

proc sql;
create table output as
select *
from input t
group by t.person, t.date
having max(t.readmission_claim) = 1
;
quit;

proc print data=output noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                        readmission_
person          date        claim

   1      2018-03-05          1     
   1      2018-03-05          0     
&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 07:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443197#M110861</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-07T07:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443204#M110863</link>
      <description>That worked! Thanks for helping a SAS noob</description>
      <pubDate>Wed, 07 Mar 2018 08:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443204#M110863</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2018-03-07T08:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443205#M110864</link>
      <description>&lt;P&gt;Thank you for noticing the error. This fixed it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 08:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-help/m-p/443205#M110864</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2018-03-07T08:21:39Z</dc:date>
    </item>
  </channel>
</rss>

