<?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: How to use only condition in sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615491#M18770</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; You are right.&amp;nbsp; I had that doubt too. I often prefer any OP's to offer us a feedback and confirm if the communication is right for us to make edit/changes if needed. So yes, some OPs are interactive while others not so much. Let's see.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 22:15:27 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-06T22:15:27Z</dc:date>
    <item>
      <title>How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615348#M18744</link>
      <description>&lt;P&gt;I have a dataset in which I am trying to find the Outlets which are selling only two category i.e 'CSP' and 'Stills' and not other categories&lt;/P&gt;&lt;P&gt;for eg:-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;24034743&lt;/TD&gt;&lt;TD&gt;CSP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;24034743&lt;/TD&gt;&lt;TD&gt;Stills&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27344795&lt;/TD&gt;&lt;TD&gt;Water&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27344795&lt;/TD&gt;&lt;TD&gt;Stills&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27344795&lt;/TD&gt;&lt;TD&gt;CSP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;24660690&lt;/TD&gt;&lt;TD&gt;CSP&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;In this outlet&amp;nbsp;24034743 sells CSP and Stills, outlet&amp;nbsp;27344795 sells&amp;nbsp; CSP,Water and Stills and outlet 24660690 sells only CSP in this case I need only outlet which sells&amp;nbsp;CSP and Stills.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried few methods not got success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me on this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option compress=yes;

data test;
input Outlet $ Category $;
Cards;
27344795	CSP
29306680	Water
29106861	Coffee
24660690	CSP
25298585	CSP
27852713	CSP
27344795	Water
24034743	CSP
24792773	Coffee
2991031	        CSP
21362260	CSP
29003700	CSP
27314730	CSP
26678079	CSP
22625435	CSP
29702708	CSP
25459917	Stills
24010565	CSP
28131642	CSP
22078107	CSP
21501108	CSP
28393563	CSP
25784580	CSP
24976068	CSP
29306680	CSP
25784580	Stills
21038003	CSP
22145937	CSP
21906503	CSP
28506284	Stills
29993536	CSP
23915168	CSP
21153504	Coffee
24981847	CSP
21977529	Water
22684050	Water
29291387	Stills
25298585	Coffee
29106861	CSP
24976068	Stills
28393563	Coffee
28506284	CSP
22078107	Stills
29106861	Stills
21906503	Stills
21501108	Coffee
29003700	Stills
29306680	Stills
28393563	Stills
27314730	Stills
27344795	Stills
28506284	Water
27933637	CSP
2991031	        Stills
28131642	Water
24034743	Stills
22078107	Water
24976068	Coffee
29306680	Coffee
26857155	CSP
21362260	Water
;
run;

proc sort data =test out=abc nodupkey;
by Outlet Category;
where Category in ('CSP','Stills') and Category not in ('Water', 'Coffee');
run;

proc sort data =test out=abc nodupkey;
by Outlet Category;
where Category in ('CSP','Stills') and Category not in ('Water', 'Coffee');
run;

data abc;
set test;
where Category not in ('Water', 'Coffee') and Category in ('CSP','Stills');
run;

proc sql;
select count(distinct outlet) from test
where Category not in ('Water', 'Coffee') and Category in ('CSP','Stills');
run;

proc sql;
select count (distinct c.Outlet) as o_count
from test as c, test as s
where c.Outlet = s.Outlet
and s.Category like '%CSP%'
and c.Category like '%Stills%';
quit;
run;

proc sql;
 create table abc as select distinct b.Outlet as outlet 
 from  test a left join test b
  on a.Outlet=b.Outlet
  and a.Category=b.Category
  where b.Category in ('CSP','Stills') and a.Category not in ('Water', 'Coffee');
  quit;
  run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 14:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615348#M18744</guid>
      <dc:creator>umeshgiri48</dc:creator>
      <dc:date>2020-01-06T14:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615352#M18745</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212787"&gt;@umeshgiri48&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one approach to do that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=test out=test_sorted;
	by Outlet Category;
run;
proc transpose data=test_sorted out=test_tr;
	by Outlet;
	var Category;
run;

data want (keep=outlet);
	set test_tr;
	Category = catx(" ",of col:);
	if find(Category,"CSP") and find(Category,"Stills") and countw(Category)=2 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jan 2020 14:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615352#M18745</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-06T14:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615365#M18747</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212787"&gt;@umeshgiri48&lt;/a&gt;&amp;nbsp; This is a natural case&amp;nbsp; for PROC SQL&amp;nbsp; and just one step if i understand your requirement correctly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
input Outlet $ Category $;
Cards;
24034743	CSP
24034743	Stills
27344795	Water
27344795	Stills
27344795	CSP
24660690	CSP
;
run;


proc sql;
create table want as
select *
from test
group by outlet
having count(distinct Category)=2 and sum(Category in ('CSP','Stills'))=2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Or I am also assuming the instead of the previous HAVING filter, the one below could be what you are after*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;having count(distinct Category)&amp;gt;1 and count(*)= sum(Category in ('CSP','Stills'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jan 2020 15:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615365#M18747</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-06T15:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615489#M18768</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; &amp;nbsp; I agree that this is a ready-made task for PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT … there is an embedded assumption in your code, namely that there are no duplicate OUTLET/CATEGORY records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, if an OUTLET has, say, 2 CSP's and 1 Still (and no other records), it won't be captured - presumably a false negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, the assumption may very well be the case.&amp;nbsp; If so, the OP would be safe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615489#M18768</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-06T22:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615491#M18770</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; You are right.&amp;nbsp; I had that doubt too. I often prefer any OP's to offer us a feedback and confirm if the communication is right for us to make edit/changes if needed. So yes, some OPs are interactive while others not so much. Let's see.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615491#M18770</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-06T22:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615552#M18777</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; this query will only provide an outlet which is having CSP and Stills but I need only those Outlets which are selling only CSP and Stills not other categories like water and etc&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 06:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615552#M18777</guid>
      <dc:creator>umeshgiri48</dc:creator>
      <dc:date>2020-01-07T06:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615555#M18778</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp; this code is fine when there are no duplicate OUTLET/CATEGORY records&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance, if an OUTLET has, say, 4 CSP's and 3 Still (and no other records), it won't be captured and we will get 0 output&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 06:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615555#M18778</guid>
      <dc:creator>umeshgiri48</dc:creator>
      <dc:date>2020-01-07T06:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615566#M18782</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212787"&gt;@umeshgiri48&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To handle this use case, you can simply add the NODUPKEY option in the proc sort as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test out=test_sorted nodupkey;
	by Outlet Category;
run;
proc transpose data=test_sorted out=test_tr;
	by Outlet;
	var Category;
run;

data want (keep=outlet);
	set test_tr;
	Category = catx(" ",of col:);
	if find(Category,"CSP") and find(Category,"Stills") and countw(Category)=2 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 06:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615566#M18782</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-07T06:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615576#M18785</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt; thanks for the solution, Is there is another way to do in Proc Sql</description>
      <pubDate>Tue, 07 Jan 2020 07:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615576#M18785</guid>
      <dc:creator>umeshgiri48</dc:creator>
      <dc:date>2020-01-07T07:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615580#M18787</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212787"&gt;@umeshgiri48&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use this for example :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select outlet
	from (select distinct *
	  	 from test
		 group by Outlet)
	group by outlet
	having count(distinct Category)=2 and sum(Category in ('CSP','Stills'))=2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615580#M18787</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-07T07:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use only condition in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615588#M18792</link>
      <description>It's not working</description>
      <pubDate>Tue, 07 Jan 2020 08:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-only-condition-in-sas/m-p/615588#M18792</guid>
      <dc:creator>umeshgiri48</dc:creator>
      <dc:date>2020-01-07T08:05:28Z</dc:date>
    </item>
  </channel>
</rss>

