<?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: (List One) minus (List Two) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611201#M178091</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table list3 as
select stock from list1
except
select stock from list2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Dec 2019 03:50:59 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-12-12T03:50:59Z</dc:date>
    <item>
      <title>(List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611194#M178088</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Curious how SAS could efficiently do the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given two text lists (say, of stock symbols) how can user subtract one list from the other?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AAAU&lt;/P&gt;
&lt;P&gt;ACIM&lt;/P&gt;
&lt;P&gt;ACWF&lt;/P&gt;
&lt;P&gt;ACWX&lt;/P&gt;
&lt;P&gt;ADRD&lt;/P&gt;
&lt;P&gt;ADRE&lt;/P&gt;
&lt;P&gt;ADRU&lt;/P&gt;
&lt;P&gt;AGG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;minus&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ACIM&lt;/P&gt;
&lt;P&gt;ACWF&lt;/P&gt;
&lt;P&gt;AGG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We assume all members of List Two are included in List One.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From reading other's posts, Proc Compare and Proc SQL both look promising.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&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;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 02:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611194#M178088</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2019-12-12T02:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611195#M178089</link>
      <description>Please let us know if you are trying to identify the text not in either of the both list.</description>
      <pubDate>Thu, 12 Dec 2019 02:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611195#M178089</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-12T02:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611196#M178090</link>
      <description>&lt;P&gt;If the expected output is to have the list of text not in list2 but in list 1 the try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input list$;
cards;
AAAU
ACIM
ACWF
ACWX
ADRD
ADRE
ADRU
AGG
;

data have2;
input list$;
cards;
ACIM
ACWF
AGG
;

proc sort data=have1;
by list;
run;

proc sort data=have2;
by list;
run;

data want;
merge have1(in=a) have2(in=b);
by list;
if a and not b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 02:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611196#M178090</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-12T02:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611201#M178091</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table list3 as
select stock from list1
except
select stock from list2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 03:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611201#M178091</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-12T03:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611202#M178092</link>
      <description>&lt;P&gt;It can be done without explicit sorting using Hash objects. Also we can use Proc Format. Here is the Hash way using the data sets given by Jag:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if _n_ = 1 then do;
      if 0 then set have2;
      declare hash h(dataset:'have2');
      h.definekey('list');
      h.definedone();
   end;
   set have1;
   if h.check() ne 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 03:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611202#M178092</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-12T03:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611203#M178093</link>
      <description>&lt;P&gt;Or:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
delete from list1
where stock in (select stock from list2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 03:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611203#M178093</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-12T03:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611215#M178098</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No mention of Proc Compare yet?&amp;nbsp; Most examples out there that seemed reasonably close to my question used Proc Compare.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PGStats looks to be offering short and efficient code.&amp;nbsp; Nice tight quick solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone do better??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 06:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611215#M178098</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2019-12-12T06:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611232#M178108</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22691"&gt;@NKormanik&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If have2 is very small compared to have1, using a hash will be in an efficient way to achieve you goal.&lt;/P&gt;
&lt;P&gt;There is no need to sort those tables or to index them prior to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input list$;
cards;
AAAU
ACIM
ACWF
ACWX
ADRD
ADRE
ADRU
AGG
;
run;

data have2;
input list$;
cards;
ACIM
ACWF
AGG
;
run;

data want;
	if _n_ = 1 then do;
			declare hash h (dataset:'have2');
			h.definekey('list');
			h.definedone();
		end;
	set have1;
	if h.find() ne 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 08:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611232#M178108</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-12T08:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611246#M178115</link>
      <description>&lt;P&gt;This is similar to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;'s "delete from" approach in that it removes observations from LIST1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list1;
modify list1 list2;
by stock;
remove;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Like PROC SQL it does &lt;EM&gt;not&lt;/EM&gt; require sorted input datasets -- despite the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If LIST1 and LIST2 are the only datasets (in the WORK/USER library) whose names start with "LIST", the MODIFY statement could be written as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;modify list:;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 10:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611246#M178115</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-12T10:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: (List One) minus (List Two)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611533#M178241</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for the record, here's my full code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*
Help given by PGStats.
Remove outdated, depricated stock symbols&lt;BR /&gt; from entire symbol list.
Use MetaStock tester to isolate the bad symbols.
Copy full symbol list to C:\0_SAS_1.  &lt;BR /&gt;Name it ... as appropriate.
Copy list of bad symbols to be removed&lt;BR /&gt; to C:\0_SAS_1.  Name it "Remove.txt".
*/

data sas_1.ETF_List;
infile "C:\0_SAS_1\ETF List.txt";
input Stocks $;
run;

data sas_1.Remove;
infile "C:\0_SAS_1\Remove.txt";
input Stocks $;
run;

proc sql;
delete from SAS_1.ETF_List
where Stocks in (select Stocks from SAS_1.Remove);
quit;

proc export
data=SAS_1.ETF_List
outfile="C:\0_SAS_1\ETF List 2.txt";
putnames=no;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="display: none; opacity: 0; position: absolute; z-index: 2147483647;" src="chrome-extension://dbkmjjclgbiooljcegcddagnddjedmed/pics/save2-32.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 08:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-One-minus-List-Two/m-p/611533#M178241</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2019-12-13T08:47:06Z</dc:date>
    </item>
  </channel>
</rss>

