<?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: Selecting all records based on a specific value for a variable. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10841#M930</link>
    <description>Flip&lt;BR /&gt;
&lt;BR /&gt;
I am trying to translate your code. My variables are ID, F and AMOUNT. I happened to use A and B as two values of F, and your a and b makes me confused.&lt;BR /&gt;
&lt;BR /&gt;
I am taking the easy way and ask you, instead of trying to solve it myself.&lt;BR /&gt;
&lt;BR /&gt;
Time ...&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
    <pubDate>Thu, 26 Mar 2009 13:46:22 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-26T13:46:22Z</dc:date>
    <item>
      <title>Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10833#M922</link>
      <description>My table has 2 variables, ID and AMOUNT. An individual can occur several times with different amounts. If at least one of an individuals amount is greater than 0 then all records should be kept for that individual in the new table.&lt;BR /&gt;
&lt;BR /&gt;
Old table&lt;BR /&gt;
&lt;BR /&gt;
ID AMOUNT&lt;BR /&gt;
1 0&lt;BR /&gt;
2 0&lt;BR /&gt;
2 1&lt;BR /&gt;
2 0&lt;BR /&gt;
3 0&lt;BR /&gt;
3 0&lt;BR /&gt;
4 1&lt;BR /&gt;
4 1&lt;BR /&gt;
4 0&lt;BR /&gt;
4 1&lt;BR /&gt;
5 0&lt;BR /&gt;
6 0&lt;BR /&gt;
6 1&lt;BR /&gt;
&lt;BR /&gt;
should become&lt;BR /&gt;
&lt;BR /&gt;
New table&lt;BR /&gt;
&lt;BR /&gt;
ID AMOUNT&lt;BR /&gt;
2 0&lt;BR /&gt;
2 1&lt;BR /&gt;
2 0&lt;BR /&gt;
4 1&lt;BR /&gt;
4 1&lt;BR /&gt;
4 0&lt;BR /&gt;
4 1&lt;BR /&gt;
6 0&lt;BR /&gt;
6 1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Is PROC SQL the appropriate procedure to use? I need some help.&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Wed, 25 Mar 2009 12:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10833#M922</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-25T12:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10834#M923</link>
      <description>Yes, proc sql would be fine but you can use a data step to do this too:&lt;BR /&gt;
&lt;BR /&gt;
data new_table;&lt;BR /&gt;
  where amount gt 0;&lt;BR /&gt;
  set old_table&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table new_table as&lt;BR /&gt;
  select *&lt;BR /&gt;
  from old_table&lt;BR /&gt;
  where amount &amp;gt;0&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;</description>
      <pubDate>Wed, 25 Mar 2009 12:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10834#M923</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-25T12:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10835#M924</link>
      <description>There was a very similar request yesterday:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=5281&amp;amp;tstart=0" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=5281&amp;amp;tstart=0&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
I think you want something like:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table new_table as&lt;BR /&gt;
select * from old_table&lt;BR /&gt;
where id in (select distinct id from old_table where amount&amp;gt;0);&lt;BR /&gt;
quit;</description>
      <pubDate>Wed, 25 Mar 2009 13:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10835#M924</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-25T13:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10836#M925</link>
      <description>Yup, I agree - having mis-read the original question! :@(</description>
      <pubDate>Wed, 25 Mar 2009 13:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10836#M925</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-25T13:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10837#M926</link>
      <description>Thank you, pznew. That worked fine.&lt;BR /&gt;
&lt;BR /&gt;
If my table hade one more variable, F, and looked like this after the PROC SQL:&lt;BR /&gt;
&lt;BR /&gt;
ID F AMOUNT&lt;BR /&gt;
2  A 0&lt;BR /&gt;
2  A 1&lt;BR /&gt;
2  B 0&lt;BR /&gt;
4  B 1&lt;BR /&gt;
4  A 1&lt;BR /&gt;
4  A 0&lt;BR /&gt;
4  A 1&lt;BR /&gt;
6  B 0&lt;BR /&gt;
6  A 1&lt;BR /&gt;
&lt;BR /&gt;
Then I would like to get those where the combination of ID and F is the same as the the one where the 0 was, like this:&lt;BR /&gt;
&lt;BR /&gt;
2  A 0 &lt;BR /&gt;
2  A 1&lt;BR /&gt;
2  B 0&lt;BR /&gt;
*** Want deleted because there is no 4 B 0 after the first PROC SQL&lt;BR /&gt;
4  A 1&lt;BR /&gt;
4  A 0&lt;BR /&gt;
4  A 1&lt;BR /&gt;
6  B 0&lt;BR /&gt;
*** Want deleted because there is no 6 A 0 after the first PROC SQL&lt;BR /&gt;
&lt;BR /&gt;
And F is not restricted to just A and B.&lt;BR /&gt;
&lt;BR /&gt;
I don't think all this could be done in the first PROC SQL, but IF, it would be great.&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Thu, 26 Mar 2009 13:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10837#M926</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T13:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10838#M927</link>
      <description>I think this was covered as well in the earlier discussion.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=5281&amp;amp;tstart=0" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=5281&amp;amp;tstart=0&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
create table no_zeros as select a.* from source as a, (select a, f from source where b=0) as b&lt;BR /&gt;
where not(a.a = b.a and b.f = a.f); &lt;BR /&gt;
&lt;BR /&gt;
(I didn't run this so I hope I didn not drop in any syntax errors)</description>
      <pubDate>Thu, 26 Mar 2009 13:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10838#M927</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T13:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10839#M928</link>
      <description>Sorry, I meant still to keep those where there was an amount greater than 0.&lt;BR /&gt;
&lt;BR /&gt;
But now I would like to keep the ones where the combination of ID and F is the same as it was where that amount could be found.&lt;BR /&gt;
&lt;BR /&gt;
So&lt;BR /&gt;
&lt;BR /&gt;
2 A 0&lt;BR /&gt;
2 A 1&lt;BR /&gt;
2 B 0&lt;BR /&gt;
4 B 1&lt;BR /&gt;
4 A 1&lt;BR /&gt;
4 A 0&lt;BR /&gt;
4 A 1&lt;BR /&gt;
6 B 0&lt;BR /&gt;
6 A 1&lt;BR /&gt;
&lt;BR /&gt;
would become&lt;BR /&gt;
&lt;BR /&gt;
2 A 0&lt;BR /&gt;
2 A 1&lt;BR /&gt;
DELETE&lt;BR /&gt;
4 B 1&lt;BR /&gt;
4 A 1&lt;BR /&gt;
4 A 0&lt;BR /&gt;
4 A 1&lt;BR /&gt;
DELETE&lt;BR /&gt;
6 A 1&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Thu, 26 Mar 2009 13:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10839#M928</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T13:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10840#M929</link>
      <description>create table no_zeros as select a.* from source as a, (select a, f from source where b&amp;gt;0) as b&lt;BR /&gt;
where (a.a = b.a and b.f = a.f);</description>
      <pubDate>Thu, 26 Mar 2009 13:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10840#M929</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T13:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10841#M930</link>
      <description>Flip&lt;BR /&gt;
&lt;BR /&gt;
I am trying to translate your code. My variables are ID, F and AMOUNT. I happened to use A and B as two values of F, and your a and b makes me confused.&lt;BR /&gt;
&lt;BR /&gt;
I am taking the easy way and ask you, instead of trying to solve it myself.&lt;BR /&gt;
&lt;BR /&gt;
Time ...&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Thu, 26 Mar 2009 13:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10841#M930</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T13:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10842#M931</link>
      <description>It appears that on this forum, the factor "time" is far too often a challenge, thereby compromising one's opportunity to learn through DOC reading, digestion, code-composition, self-diagnosis and interpretation.  How unfortunate.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 26 Mar 2009 13:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10842#M931</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-26T13:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10843#M932</link>
      <description>In SQL &lt;BR /&gt;
table before the dot variable after&lt;BR /&gt;
dataset alias . variable&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
 table.field&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
create table no_zeros as select a.* from source as a, (select amount, f from source where b&amp;gt;0) as b&lt;BR /&gt;
where (a.amount = b.amount and b.f = a.f);</description>
      <pubDate>Thu, 26 Mar 2009 14:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10843#M932</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T14:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10844#M933</link>
      <description>I agree with mr Barry that it's unfortunate.&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Fri, 27 Mar 2009 07:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10844#M933</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T07:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10845#M934</link>
      <description>Flip&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
My programming is running now.&lt;BR /&gt;
&lt;BR /&gt;
And it keeps on running. For more than 5 minutes now.&lt;BR /&gt;
&lt;BR /&gt;
My table has more than 500 000 records. Isn't PROC SQL appropriate with so many records?&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Fri, 27 Mar 2009 13:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10845#M934</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T13:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all records based on a specific value for a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10846#M935</link>
      <description>A sub querry may at times be inefficient.&lt;BR /&gt;
You could try creating a work table of those IDs to keep (or delete) and do an outer join.</description>
      <pubDate>Fri, 27 Mar 2009 14:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-all-records-based-on-a-specific-value-for-a-variable/m-p/10846#M935</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-27T14:07:20Z</dc:date>
    </item>
  </channel>
</rss>

