<?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: Subset by group that meets two conditions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861856#M82575</link>
    <description>&lt;P&gt;I have a follow-up question. Is it possible to create a variable (goal) following the statement "having max(type1)=1 and max(type2)=1" that will be goal=1. Something like if (having statement) then goal=1. I am aware there will only be ones for this newly created variable. But we need this variable so we can then merge with other datasets and then filter rows what will be goal=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did this and it worked, but is this the right way?&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select * , 1 as goal from test&lt;BR /&gt;group by store&lt;BR /&gt;having max(type1)=1 and max(type2)=1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 22:10:29 GMT</pubDate>
    <dc:creator>ANKH1</dc:creator>
    <dc:date>2023-03-01T22:10:29Z</dc:date>
    <item>
      <title>Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861794#M82557</link>
      <description>&lt;P&gt;I have this dataset&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input store$ type1 type2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1 0&lt;BR /&gt;1 0 1&lt;BR /&gt;2 0 0&lt;BR /&gt;2 0 1&lt;BR /&gt;3 1 0&lt;BR /&gt;3 0 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need to only filter stores that meet both type1=1 and type2=1. In this case, only store 1 satisfies this condition.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 17:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861794#M82557</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T17:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861803#M82558</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;We need to only filter stores that meet both type1=1 and type2=1. In this case, only store 1 satisfies this condition.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;I don't see any such store satisfying the condition in your data.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 18:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861803#M82558</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-01T18:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861811#M82563</link>
      <description>Sorry, I should've explain more. From the same store, first observation: type1 needs to be 1 and second observation: type2 needs to be 1.</description>
      <pubDate>Wed, 01 Mar 2023 18:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861811#M82563</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T18:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861813#M82564</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class store;
    var type1 type2;
    output out=intermediate sum=;
run;
data want;
    set intermediate;
    where type1=1 and type2=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2023 18:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861813#M82564</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-01T18:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861814#M82565</link>
      <description>&lt;P&gt;If you prefer to use SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * from test
group by store
having max(type1)=1 and max(type2)=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2023 18:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861814#M82565</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-03-01T18:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861815#M82566</link>
      <description>Thanks, it works. But to simplify things, I didn't include other variables in the datalines that are part of the dataset. Is there a way to keep all columns?</description>
      <pubDate>Wed, 01 Mar 2023 18:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861815#M82566</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T18:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861817#M82567</link>
      <description>Thanks! Just one question what does max do in this case if you are already saying type1=1?</description>
      <pubDate>Wed, 01 Mar 2023 18:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861817#M82567</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T18:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861820#M82569</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks, it works. But to simplify things, I didn't include other variables in the datalines that are part of the dataset. Is there a way to keep all columns?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is a good idea to write a thorough problem description. Then we don't have to do "I don't understand"—"Oh thank you for the explanation" — "Here's code that works" — "No it doesn't work for the real problem" dance. Yes of course, there are ways to keep all columns, and I see that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;has provided an alternative, so I won't bother.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 18:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861820#M82569</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-01T18:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861822#M82570</link>
      <description>Apologies and noted.</description>
      <pubDate>Wed, 01 Mar 2023 19:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861822#M82570</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T19:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861831#M82573</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Max(type1)=1&lt;/STRONG&gt; requests stores for which the maximum value of &lt;EM&gt;type1&lt;/EM&gt; is one, so that it is equal to one for at least one observation. &lt;/P&gt;
&lt;P&gt;Note: the code assumes that &lt;EM&gt;type1&lt;/EM&gt; and &lt;EM&gt;type2&lt;/EM&gt; only take values 0 or 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 19:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861831#M82573</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-03-01T19:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861833#M82574</link>
      <description>Thank you!</description>
      <pubDate>Wed, 01 Mar 2023 19:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861833#M82574</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T19:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subset by group that meets two conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861856#M82575</link>
      <description>&lt;P&gt;I have a follow-up question. Is it possible to create a variable (goal) following the statement "having max(type1)=1 and max(type2)=1" that will be goal=1. Something like if (having statement) then goal=1. I am aware there will only be ones for this newly created variable. But we need this variable so we can then merge with other datasets and then filter rows what will be goal=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did this and it worked, but is this the right way?&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select * , 1 as goal from test&lt;BR /&gt;group by store&lt;BR /&gt;having max(type1)=1 and max(type2)=1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 22:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subset-by-group-that-meets-two-conditions/m-p/861856#M82575</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-03-01T22:10:29Z</dc:date>
    </item>
  </channel>
</rss>

