<?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: need those animal which are not in city in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773072#M245522</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp; &amp;nbsp;I wouldn't worry about not seeing the SQL solution.&amp;nbsp; It sure wasn't readily apparent to me!&amp;nbsp; &amp;nbsp;After futzing with it, I decided if you made a cartesian list of distinct cities and animals you should be able to left join that to the data to see what is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table animals as
	select distinct animal
	from have;

	create table cities as
	select distinct city
	from have;

	create table cartesianlist as 
	select a.city, b.animal 
	from cities a, animals b;

	select a.city, a.animal
	from cartesianlist a
	left join have b on a.city = b.city and a.animal = b.animal 
	where b.animal is null
	order by a.city, a.animal;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output is&lt;/P&gt;
&lt;DIV&gt;&lt;BR /&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;city&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;animal&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;chennai&lt;/TD&gt;
&lt;TD&gt;cat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;chennai&lt;/TD&gt;
&lt;TD class="b data"&gt;lion&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;delhi&lt;/TD&gt;
&lt;TD class="b data"&gt;bear&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;delhi&lt;/TD&gt;
&lt;TD class="b data"&gt;mouse&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;mumbai&lt;/TD&gt;
&lt;TD class="b data"&gt;dog&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;mumbai&lt;/TD&gt;
&lt;TD class="b data"&gt;lion&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like the sparse thing better.&amp;nbsp; Never used that before.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp; The web says "the SPARSE option provides 'all possible combinations of&lt;BR /&gt;levels of the variables in the table, even when some&lt;BR /&gt;combination levels do not occur in the data.'&lt;/P&gt;
&lt;P&gt;All possible combinations is essentially a Cartesian join.&amp;nbsp; So that makes sense.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Oct 2021 16:58:19 GMT</pubDate>
    <dc:creator>HB</dc:creator>
    <dc:date>2021-10-08T16:58:19Z</dc:date>
    <item>
      <title>need those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773036#M245502</link>
      <description>&lt;P&gt;animal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;city&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;delhi&lt;/P&gt;
&lt;P&gt;cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;delhi&lt;/P&gt;
&lt;P&gt;lion&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; delhi&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;bear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mumbai&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mumbai&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;mouse&amp;nbsp; &amp;nbsp; &amp;nbsp;mumbai&lt;/P&gt;
&lt;P&gt;dog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chennai&lt;/P&gt;
&lt;P&gt;mouse&amp;nbsp; &amp;nbsp; &amp;nbsp; chennai&lt;/P&gt;
&lt;P&gt;bear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chennai&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output&amp;nbsp;&lt;/P&gt;
&lt;P&gt;animal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;city&amp;nbsp;&lt;/P&gt;
&lt;P&gt;delhi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bear&lt;/P&gt;
&lt;P&gt;delhi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mouse&lt;/P&gt;
&lt;P&gt;mumbai&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dog&lt;/P&gt;
&lt;P&gt;mumbai&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lion&lt;/P&gt;
&lt;P&gt;chennai&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cat&lt;/P&gt;
&lt;P&gt;chennai&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lion&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 13:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773036#M245502</guid>
      <dc:creator>aanan1417</dc:creator>
      <dc:date>2021-10-08T13:50:00Z</dc:date>
    </item>
    <item>
      <title>come out those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773038#M245527</link>
      <description>&lt;P&gt;data a;&lt;BR /&gt;input animal $ city $;&lt;BR /&gt;datalines;&lt;BR /&gt;dog delhi&lt;BR /&gt;cat delhi&lt;BR /&gt;lion delhi&lt;BR /&gt;bear mumbai&lt;BR /&gt;cat mumbai&lt;BR /&gt;mouse mumbai&lt;BR /&gt;dog chennai&lt;BR /&gt;mouse chennai&lt;BR /&gt;bear chennai&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;input animal $ city $;&lt;BR /&gt;datalines;&lt;BR /&gt;bear delhi&lt;BR /&gt;mouse delhi&lt;BR /&gt;dog mumbai&lt;BR /&gt;lion mumbai&lt;BR /&gt;cat chennai&lt;BR /&gt;lion chennai&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 14:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773038#M245527</guid>
      <dc:creator>aanan1417</dc:creator>
      <dc:date>2021-10-08T14:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: need those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773040#M245504</link>
      <description>&lt;P&gt;I really love the PROC FREQ `sparse` option for these. You can do it in PROC SQL, too, but I'm not the best PROC SQL programmer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input animal :$5. city :$7.;
datalines;
dog delhi
cat delhi
lion delhi
bear mumbai
cat mumbai
mouse mumbai
dog chennai
mouse chennai
bear chennai
;
run;

proc freq
	data = have;
		tables animal * city / list sparse out = want (keep = animal city count where = (count = 0));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs 	animal 	city 	COUNT
1 	bear 	delhi 	0
2 	cat 	chennai 	0
3 	dog 	mumbai 	0
4 	lion 	chennai 	0
5 	lion 	mumbai 	0
6 	mouse 	delhi 	0&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Oct 2021 14:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773040#M245504</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-10-08T14:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: come out those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773041#M245528</link>
      <description>&lt;P&gt;Do not post the same question twice. All replies should go to your other thread at &lt;A href="https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/td-p/773036/" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/td-p/773036/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 14:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773041#M245528</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-08T14:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: need those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773072#M245522</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp; &amp;nbsp;I wouldn't worry about not seeing the SQL solution.&amp;nbsp; It sure wasn't readily apparent to me!&amp;nbsp; &amp;nbsp;After futzing with it, I decided if you made a cartesian list of distinct cities and animals you should be able to left join that to the data to see what is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table animals as
	select distinct animal
	from have;

	create table cities as
	select distinct city
	from have;

	create table cartesianlist as 
	select a.city, b.animal 
	from cities a, animals b;

	select a.city, a.animal
	from cartesianlist a
	left join have b on a.city = b.city and a.animal = b.animal 
	where b.animal is null
	order by a.city, a.animal;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output is&lt;/P&gt;
&lt;DIV&gt;&lt;BR /&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;city&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;animal&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;chennai&lt;/TD&gt;
&lt;TD&gt;cat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;chennai&lt;/TD&gt;
&lt;TD class="b data"&gt;lion&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;delhi&lt;/TD&gt;
&lt;TD class="b data"&gt;bear&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;delhi&lt;/TD&gt;
&lt;TD class="b data"&gt;mouse&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;mumbai&lt;/TD&gt;
&lt;TD class="b data"&gt;dog&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;mumbai&lt;/TD&gt;
&lt;TD class="b data"&gt;lion&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like the sparse thing better.&amp;nbsp; Never used that before.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp; The web says "the SPARSE option provides 'all possible combinations of&lt;BR /&gt;levels of the variables in the table, even when some&lt;BR /&gt;combination levels do not occur in the data.'&lt;/P&gt;
&lt;P&gt;All possible combinations is essentially a Cartesian join.&amp;nbsp; So that makes sense.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 16:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773072#M245522</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2021-10-08T16:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: need those animal which are not in city</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773263#M245616</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input animal :$5. city :$7.;
datalines;
dog delhi
cat delhi
lion delhi
bear mumbai
cat mumbai
mouse mumbai
dog chennai
mouse chennai
bear chennai
;
run;
proc sql;
create table want as
select a.*
 from (select * from (select distinct animal from have),(select distinct city from have)) as a 
 natural left join have as b
 where b.animal is missing;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Oct 2021 10:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-those-animal-which-are-not-in-city/m-p/773263#M245616</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-10T10:40:55Z</dc:date>
    </item>
  </channel>
</rss>

