<?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: To cross join and filter same step in datastep language in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703571#M215603</link>
    <description>&lt;P&gt;Do not use a subsetting IF. It will immediately exit the DO loop and the data step iteration.&lt;/P&gt;
&lt;P&gt;Consider loading your product table into temporary arrays (one per column). That will speed up the DO loop significantly.&lt;/P&gt;
&lt;P&gt;Run a test with a small subset of your customer table, to get a feel for the output. It may very well be that you end up with (close to) 3 billion observations.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2020 09:18:16 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-04T09:18:16Z</dc:date>
    <item>
      <title>To cross join and filter same step in datastep language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703362#M215492</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am using SAS EG 7.1.&lt;/P&gt;&lt;P&gt;I have two tables called customer and product. I want to cross join these tables and filtering in same step. View of input tables and table that i want to create is as below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Untitled.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52282i6B1995E8FD14E237/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In real; customer table have&amp;nbsp;approx 10 millions rows, product table have&amp;nbsp;approx 300 rows and i prefer to use datastep language because of it faster than proc sql language and i want to filter in same step for more efficiency.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried below code but it doesn't work as i want.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set customer;
do i = 1 to n;
	set work.product point = i nobs = n;
	if cust_var2 ne prod_id and cust_var1 le prod_var1;
	output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Actually proc sql language that below works but it is very slow because of table size.&lt;/P&gt;&lt;PRE&gt;proc sql;
create table want3 as select
*
from customer t1, product t2
where 
t1.cust_var2 ne t2.prod_id and t1.cust_var1 le t2.prod_var1;
quit;&lt;/PRE&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data product;
infile datalines delimiter=',';
input prod_id product_name $ prod_var1;
datalines;
1, aaa, 100
2, bbb, 250
3, ccc, 200
4, ddd, 100
5, ddd, 250
;
run;

data customer;
infile datalines delimiter=',';
input cust_id cust_var1 cust_var2;
datalines;
1, 100, 2
2, 200, 5
3, 300, 5
;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Dec 2020 13:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703362#M215492</guid>
      <dc:creator>maozsoy</dc:creator>
      <dc:date>2020-12-03T13:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: To cross join and filter same step in datastep language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703363#M215493</link>
      <description>&lt;P&gt;If you only have 300 products then use a data step hash object to hold that table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your join criteria appears very wonky.&amp;nbsp; Please describe the business rule you are trying to code. Also provide desired output from the given input data.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 14:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703363#M215493</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-03T14:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: To cross join and filter same step in datastep language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703568#M215601</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data product;
	infile datalines delimiter=',';
	input prod_id product_name $ prod_var1;
	datalines;
1, aaa, 100
2, bbb, 250
3, ccc, 200
4, ddd, 100
5, ddd, 250
;
run;

data customer;
	infile datalines delimiter=',';
	input cust_id cust_var1 cust_var2;
	datalines;
1, 100, 2
2, 200, 5
3, 300, 5
;
run;

data want;
	set customer;

	do j=1 to nobs2;
		set work.product point=j nobs=nobs2;
		if cust_var2 ne prod_id and cust_var1 le prod_var1 then
			output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2020 08:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703568#M215601</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-12-04T08:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: To cross join and filter same step in datastep language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703571#M215603</link>
      <description>&lt;P&gt;Do not use a subsetting IF. It will immediately exit the DO loop and the data step iteration.&lt;/P&gt;
&lt;P&gt;Consider loading your product table into temporary arrays (one per column). That will speed up the DO loop significantly.&lt;/P&gt;
&lt;P&gt;Run a test with a small subset of your customer table, to get a feel for the output. It may very well be that you end up with (close to) 3 billion observations.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703571#M215603</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-04T09:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: To cross join and filter same step in datastep language</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703580#M215606</link>
      <description>&lt;P&gt;See here an application of temporary arrays to your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data product;
infile datalines delimiter=',';
input prod_id product_name $ prod_var1;
datalines;
1, aaa, 100
2, bbb, 250
3, ccc, 200
4, ddd, 100
5, ddd, 250
;

data customer;
infile datalines delimiter=',';
input cust_id cust_var1 cust_var2;
datalines;
1, 100, 2
2, 200, 5
3, 300, 5
;

proc sort data=product;
by descending prod_var1;
run;

proc sql noprint;
select nobs into :nobs
from dictionary.tables
where libname = "WORK" and memname = "PRODUCT";
quit;

data want;
set customer;
if _n_ = 1
then do;
  array p_id {&amp;amp;nobs.} _temporary_;
  array p_name {&amp;amp;nobs.} $8 _temporary_;
  array p_var1 {&amp;amp;nobs.} _temporary_;
  do i = 1 to &amp;amp;nobs.;
    set product;
    p_id{i} = prod_id;
    p_name{i} = product_name;
    p_var1{i} = prod_var1;
  end;
end;
do i = 1 to dim(p_id);
  if p_id{i} ne cust_var2 and cust_var1 le p_var1{i}
  then do;
    prod_id = p_id{i};
    product_name = p_name{i};
    prod_var1 = p_var1{i};
    output;
  end;
  if cust_var1 gt p_var1{i} then leave;
end;
drop i;
run;

proc sort data=want;
by cust_id prod_id;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;cust_id	cust_var1	cust_var2	prod_id	product_name	prod_var1
1	100	2	1	aaa	100
1	100	2	3	ccc	200
1	100	2	4	ddd	100
1	100	2	5	ddd	250
2	200	5	2	bbb	250
2	200	5	3	ccc	200
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 10:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-cross-join-and-filter-same-step-in-datastep-language/m-p/703580#M215606</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-04T10:49:47Z</dc:date>
    </item>
  </channel>
</rss>

