<?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: Cartesian Product with filters using Datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403543#M98060</link>
    <description>&lt;P&gt;my problem is that I need to only apply filters if they are not missing, and the data step aproach seemed a better way to avoid adding so many logical conditions but I'll try implementing it that way then...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another reason I was trying to implement the code this way is because I understand the way data is procesed in data step (as much as one can understand during 4 months of work xD) and thought it would be a very big improvement in performance.&lt;/P&gt;&lt;P&gt;I am not familiar with the way sql processes data, will this augment the performance significantly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just by curiosity, do you know why my code isn't working properly?&lt;/P&gt;</description>
    <pubDate>Thu, 12 Oct 2017 13:45:59 GMT</pubDate>
    <dc:creator>Ricardo_Neves</dc:creator>
    <dc:date>2017-10-12T13:45:59Z</dc:date>
    <item>
      <title>Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403490#M98052</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have a process where I do a Cartesian product of 2 tables&amp;nbsp; (one with data and one with parameters) using proc sql and then I use data step to apply the needed filters so that at the end only the lines where the data matches the parameter remain.&lt;BR /&gt;&lt;BR /&gt;As you can imagine this is a very inefficient process and so I'm trying to use a datastep approach&amp;nbsp; to apply the filters during the cross join so that the process becomes more efficient. But unfortunately it doesn't seem to be working since and don't get the same results in both cases. In fact, instead of getting something between 1.000 - 10.000 observations, I get only 25!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the code mentioned here &lt;A href="http://support.sas.com/kb/24/652.html" target="_self"&gt;http://support.sas.com/kb/24/652.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here is a sample of what I'm doing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    data campanha_000_testes;
    set base
      do i=1 to n;

        set parameter point=i nobs=n;


    if id = 000 and SYSTEM NE 'BBBB' then delete;

        
            if not missing('oferta Origem'n) then
                do;
                    if compress('oferta Origem'n) = compress(pack_dsc);
                end;

                    if find(RP_ID_EXCLUDE,compress(put(pack_cod,10.))) then delete;
                end;

            if not missing(Desconto_mens_max) then
                do;
                    if Desconto_mens_min &amp;lt;= Beneficio &amp;lt;=Desconto_mens_max;
                end;

            if not missing(mensalidade_maxima) then
                do;
                    *distinguir a abordagem;
                    if abordagem in ('Client','Conta') and id ne 303 then
                        do;
                            if mensalidade_minima &amp;lt; mens_liq_conta &amp;lt;= mensalidade_maxima;
                        end;
                    else if compress(abordagem) in ('Client','Conta') and id = 303 then
                        do;
                            if mensalidade_minima &amp;lt; mens_liq_im_conta &amp;lt;= mensalidade_maxima;
                        end;
                    else if abordagem = 'NIF' then
                        do;
                            if mensalidade_minima &amp;lt; mens_liq_NIF &amp;lt;= mensalidade_maxima;
                        end;
                    else
                        do;
                            if Mensalidade_Minima &amp;lt; Mensalidade_Liq_Siva &amp;lt;= Mensalidade_maxima;
                        end;
                end;

            output;

      end;

        run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any ideas on how to perform this?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 10:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403490#M98052</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-10-12T10:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403499#M98055</link>
      <description>&lt;P&gt;Could you please post the original code with SQL and data step? I think it should be possible to include the condition from the data step into the SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 11:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403499#M98055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-12T11:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403504#M98056</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the original code, the data step part is almost identical I just do a simple Cartesian product with proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample: (I have much more conditions than these)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table campaign_&amp;amp;id. as
select *
from work.base 
cross join parametro;
quit;

	data campanha_000_testes;
	set ampaign_&amp;amp;id.;
if id = 000 and SYSTEM NE 'BBBB' then delete;
	
		if not missing('oferta Origem'n) then
			do;
				if compress('oferta Origem'n) = compress(pack_dsc);
			end;

				if find(RP_ID_EXCLUDE,compress(put(pack_cod,10.))) then delete;
			end;

		if not missing(Desconto_mens_max) then
			do;
				if Desconto_mens_min &amp;lt;= Beneficio &amp;lt;=Desconto_mens_max;
			end;

		if not missing(mensalidade_maxima) then
			do;
				*distinguir a abordagem;
				if abordagem in ('Client','Conta') and id ne 303 then
					do;
						if mensalidade_minima &amp;lt; mens_liq_conta &amp;lt;= mensalidade_maxima;
					end;
				else if compress(abordagem) in ('Client','Conta') and id = 303 then
					do;
						if mensalidade_minima &amp;lt; mens_liq_im_conta &amp;lt;= mensalidade_maxima;
					end;
				else if abordagem = 'NIF' then
					do;
						if mensalidade_minima &amp;lt; mens_liq_NIF &amp;lt;= mensalidade_maxima;
					end;
				else
					do;
						if Mensalidade_Minima &amp;lt; Mensalidade_Liq_Siva &amp;lt;= Mensalidade_maxima;
					end;
			end;



	run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 11:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403504#M98056</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-10-12T11:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403515#M98058</link>
      <description>&lt;P&gt;I've included part of your conditions as a where in the SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table campaign_&amp;amp;id. as
select *
from work.base 
cross join parametro
where
  (id = 000 or SYSTEM NE 'BBBB' or not find(RP_ID_EXCLUDE,compress(put(pack_cod,10.))))
  and (
    (missing('oferta Origem'n) or compress('oferta Origem'n) = compress(pack_dsc))
    or
    (missing(Desconto_mens_max) or (Desconto_mens_min &amp;gt; Beneficio or Beneficio &amp;gt; Desconto_mens_max))
  )
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to apply DeMorgans law repeatedly when changing excluding conditions to including conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS your data step has a surplus end; after the second delete statement. Or there's a missing if .... do.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 12:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403515#M98058</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-12T12:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403543#M98060</link>
      <description>&lt;P&gt;my problem is that I need to only apply filters if they are not missing, and the data step aproach seemed a better way to avoid adding so many logical conditions but I'll try implementing it that way then...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another reason I was trying to implement the code this way is because I understand the way data is procesed in data step (as much as one can understand during 4 months of work xD) and thought it would be a very big improvement in performance.&lt;/P&gt;&lt;P&gt;I am not familiar with the way sql processes data, will this augment the performance significantly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just by curiosity, do you know why my code isn't working properly?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 13:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403543#M98060</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-10-12T13:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403546#M98061</link>
      <description>&lt;P&gt;Your best method is to start simple (with a single condition) and add conditions, so you can watch the progress in terms of growing in/exclusion.&lt;/P&gt;
&lt;P&gt;Trying to solve a problem in a "giant leap" fashion usually ends with pain. Use small steps instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If tests are taking too much time/too much space, create subsets of your datasets for testing first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 13:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403546#M98061</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-12T13:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403553#M98062</link>
      <description>thanks for the advice, I'll do just that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 12 Oct 2017 13:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403553#M98062</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-10-12T13:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product with filters using Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403607#M98079</link>
      <description>&lt;P&gt;BTW if I think that applying De Morgan's law to&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; id = 000 and SYSTEM NE 'BBBB' then delete&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;we should get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(id ^= 320 or SOURCE_SYSTEM_DSC ='BSCS')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 16:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-with-filters-using-Datastep/m-p/403607#M98079</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-10-12T16:11:58Z</dc:date>
    </item>
  </channel>
</rss>

