<?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: Queury in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761058#M240759</link>
    <description>&lt;P&gt;Well, your second method is a data step.&amp;nbsp; Inside the data step, you have a WHERE with a Select.&amp;nbsp; As far as I know, Select is valid in Proc SQL but is not valid in a Data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are multiple ways you&amp;nbsp; could get it working including a merge, a hash table, or arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given what you've already got, perhaps a merge is simplest.&amp;nbsp; Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc	SORT	DATA=Have;
	BY	IP	CustomerID;
RUN;

Proc	SORT	DATA=Tbl1;
	BY	IP;
RUN;

Data wanted_way2_merge;
	MERGE	Have	(IN	=	Have)
			Tbl1	(IN	=	IP_List);
		BY	IP;
	IF	Have and IP_List;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 05:35:45 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-08-12T05:35:45Z</dc:date>
    <item>
      <title>Queury</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761057#M240758</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with list of customer accounts and ID.&lt;/P&gt;
&lt;P&gt;(Each customer can be owned by multiple ID's and specific ID can be also in multiple accounts).&lt;/P&gt;
&lt;P&gt;I want to select rows from "have data set"&amp;nbsp; of all ID's&amp;nbsp; of customer&amp;nbsp; 1234567 .&lt;/P&gt;
&lt;P&gt;Way1 of solution i working well.&lt;/P&gt;
&lt;P&gt;I want to ask why way2 is not working well and what is the way to fix it?&lt;/P&gt;
&lt;P&gt;Are there other ways to solve it to get the wanted data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&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;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;
input IP customerID;
cards;
111 1234567
222 1234567
333 8788888
444 8798777
555 8765432
222 8765432
222 7654221
111 8273774
;
Run;

PROC SQL;
	create table tbl1  as
	select distinct IP  	   
	from  have
	where customerID=1234567
;
QUIT;

PROC SQL;
	create table wanted_way1  as
	select a.* 	   
	from  have as a
	inner join tbl1 as b
	on a.IP=b.IP
;
QUIT;

Data wanted_way2;
set have(where=(IP IN (select  distinct IP from  have 	where customerID=1234567)));
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 05:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761057#M240758</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-12T05:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Queury</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761058#M240759</link>
      <description>&lt;P&gt;Well, your second method is a data step.&amp;nbsp; Inside the data step, you have a WHERE with a Select.&amp;nbsp; As far as I know, Select is valid in Proc SQL but is not valid in a Data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are multiple ways you&amp;nbsp; could get it working including a merge, a hash table, or arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given what you've already got, perhaps a merge is simplest.&amp;nbsp; Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc	SORT	DATA=Have;
	BY	IP	CustomerID;
RUN;

Proc	SORT	DATA=Tbl1;
	BY	IP;
RUN;

Data wanted_way2_merge;
	MERGE	Have	(IN	=	Have)
			Tbl1	(IN	=	IP_List);
		BY	IP;
	IF	Have and IP_List;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 05:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761058#M240759</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-12T05:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Queury</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761061#M240761</link>
      <description>&lt;P&gt;And here are examples using an array and a hash table below. Note that for the array I inserted&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%LET IP_Cnt = &amp;amp;SQLOBS;&lt;/FONT&gt; right after the SQL that creates Tbl1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, now you have four methods:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;SQL&lt;/LI&gt;
&lt;LI&gt;A merge&lt;/LI&gt;
&lt;LI&gt;An array&lt;/LI&gt;
&lt;LI&gt;A hash table&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Take your pick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data wanted_way2_array;
	DROP	_:;
	IF	_N_	=	1	THEN
		DO;
			DO	_i	=	1	TO	&amp;amp;IP_Cnt;
				SET	Tbl1;
				ARRAY	IP_List	{&amp;amp;IP_Cnt}	_TEMPORARY_;
				IP_List{_i}	=	IP;
			END;
		END;
	SET	Have;
	IF	IP	IN	IP_List;
Run;

Data wanted_way2_hash;
	IF	0			THEN
		SET	Tbl1;
	IF	_N_	=	1	THEN
		DO;
			DECLARE	Hash	h_IP_List(DATASET: 	'Tbl1');
							h_IP_List.DEFINEKEY	('IP');
							h_IP_List.DEFINEDONE();
		END;
	SET	Have;
	IF	h_IP_List.FIND()	=	0;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 05:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761061#M240761</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-12T05:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Queury</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761090#M240776</link>
      <description>&lt;P&gt;Way 2 is not just "not working well", it doesn't work at all!&lt;/P&gt;
&lt;P&gt;Please follow Maxim 2 and&amp;nbsp;&lt;STRONG&gt;read the log!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use a WHERE= in a data step, you need an intermediate step and a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct ip into :iplist separated by ","
from have
where customerID=1234567;
quit;

data wanted_way2;
set have (where=(ip in (&amp;amp;iplist.)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 08:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Queury/m-p/761090#M240776</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-12T08:24:17Z</dc:date>
    </item>
  </channel>
</rss>

