<?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: Sub Query with Data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301271#M63717</link>
    <description>&lt;P&gt;Can you post sample data for testing? I'm fairly certain I understand the query but wouldn't bet on it. Especially when it can be easily tested. Cross joins are an interesting beast in a data step.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Sep 2016 13:44:50 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-09-28T13:44:50Z</dc:date>
    <item>
      <title>Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301253#M63711</link>
      <description>&lt;P&gt;Hi mates,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can i transform this proc sql in data step, to check witch one is faster ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE MMM2 AS
	SELECT DISTINCT A.X_ACCT_KEY,	(	SELECT B.IND_QTD_SMS
										FROM MMM B
										WHERE B.X_ACCT_KEY = A.X_ACCT_KEY AND
											  B.IND_QTD_SMS NOT IN ('0', '')
									) AS IND_SMS,
									(	SELECT B.IND_QTD_EMAIL
										FROM MMM B
										WHERE B.X_ACCT_KEY = A.X_ACCT_KEY AND
											  B.IND_QTD_EMAIL NOT IN ('0', '')
									) AS IND_EMAIL	
	FROM MMM A;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301253#M63711</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2016-09-28T13:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301268#M63716</link>
      <description>&lt;P&gt;I don't have the time to program this, but here are some questions to consider that will make life easier for some of the other posters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Evidently you can have multiple records per X_ACCT_KEY.&amp;nbsp; In that case, what matches do you want to keep?&amp;nbsp; For example, what if the same incoming record has both IND_QTD_SMS='0' and IND_QTS_EMAIL='12345'?&amp;nbsp; What if a second record for the same X_ACCT_KEY has both IND_QTD_SMS='2458' and IND_QTS_EMAIL=' '?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301268#M63716</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-28T13:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301271#M63717</link>
      <description>&lt;P&gt;Can you post sample data for testing? I'm fairly certain I understand the query but wouldn't bet on it. Especially when it can be easily tested. Cross joins are an interesting beast in a data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301271#M63717</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-28T13:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301272#M63718</link>
      <description>&lt;P&gt;I want to transform this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | SMS &amp;nbsp;| &amp;nbsp; Email&lt;/P&gt;
&lt;P&gt;6456545 &amp;nbsp; | &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; | &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;6456545 &amp;nbsp; | &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Into this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | SMS &amp;nbsp;| &amp;nbsp; Email&lt;/P&gt;
&lt;P&gt;6456545 &amp;nbsp; | &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; | &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this proc sql i can do this, but it takes a long time to run.&lt;/P&gt;
&lt;P&gt;I'd like to test with datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301272#M63718</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2016-09-28T13:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301277#M63721</link>
      <description>&lt;P&gt;Sorry, what is the question, we don't do contract work here? &amp;nbsp;At a breif glance, datastep each subquery for the where clause, then merge all three datasets, then sort nodupkey.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301277#M63721</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-28T13:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301301#M63726</link>
      <description>&lt;P&gt;I believe this will work, but without data to test it's hard to say for certain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MMM2;
	set MMM;
	keep X_ACCT_KEY IND_SMS IND_EMAIL;
	if IND_QTD_SMS IN ('0', '') then IND_SMS=''; else IND_SMS=IND_QTD_SMS;
	if IND_QTD_EMAIL IN ('0', '') then IND_EMAIL=''; else IND_EMAIL=IND_QTD_EMAIL;
run;

proc sort noduplicates; by X_ACCT_KEY IND_SMS IND_EMAIL; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2016 18:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301301#M63726</guid>
      <dc:creator>titus</dc:creator>
      <dc:date>2016-09-28T18:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301305#M63727</link>
      <description>&lt;P&gt;OK, given your subsequent description of the goal you are trying to reach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mmm2;&lt;/P&gt;
&lt;P&gt;set mmm;&lt;/P&gt;
&lt;P&gt;by x_acct_key;&lt;/P&gt;
&lt;P&gt;if ind_qtd_sms not in ('0', ' ') then new_sms=ind_qtd_sms;&lt;/P&gt;
&lt;P&gt;if ind_qtd_email not in ('0', ' ') then new_email = ind_qts_email;&lt;/P&gt;
&lt;P&gt;retain new_sms new_email;&lt;/P&gt;
&lt;P&gt;if last.x_aact_key;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;drop ind_qtd_sms ind_qts_email;&lt;/P&gt;
&lt;P&gt;rename new_sms = ind_qtd_sms new_email = ind_qts_email;&lt;/P&gt;
&lt;P&gt;new_sms=' ';&lt;/P&gt;
&lt;P&gt;new_email=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It requires that your data set is already sorted, but virtually any DATA step approach will require that.&amp;nbsp; If there are multiple records (not just 2) for an account key, you still end up with only one record for the account key.&amp;nbsp; And it should be MUCH faster than the SQL approach.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 14:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301305#M63727</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-28T14:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301387#M63768</link>
      <description>&lt;P&gt;Given your sample data, unless you've oversimplified wouldn't it be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table want as&lt;/P&gt;
&lt;P&gt;select key, max(sms) as sms, max(email) as email&lt;/P&gt;
&lt;P&gt;from have&lt;/P&gt;
&lt;P&gt;group by key;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;update have(obs=0) have;&lt;/P&gt;
&lt;P&gt;by key;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 19:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301387#M63768</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-28T19:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301395#M63772</link>
      <description>&lt;P&gt;Reeza, the possibility of '0' in the data (which must be ignored ... see the original post) complicates things.&amp;nbsp; In the case of UPDATE, there's an obvious problem where '0' could replace a valid value.&amp;nbsp; In the case of SQL, it depends on both the operating system and what might be in the realm of valid values.&amp;nbsp; On some operating systems, '0' is lower than letters.&amp;nbsp; On some, it is greater.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 20:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301395#M63772</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-28T20:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301760#M63914</link>
      <description>&lt;P&gt;I solved this by creating two separated data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA SMS_30; SET TEST_30D_V3 (WHERE=(CHANNEL_CD EQ '_MP') DROP=IND_QTD_EMAIL);RUN;&lt;BR /&gt;DATA EMAIL_30;SET TEST_30D_V3 (WHERE=(CHANNEL_CD EQ '_EM') DROP=IND_QTD_SMS);RUN;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=TEST_30D_V3; &lt;BR /&gt; BY X_ACCT_KEY;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=SMS_30; &lt;BR /&gt; BY X_ACCT_KEY;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=EMAIL_30; &lt;BR /&gt; BY X_ACCT_KEY;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;DATA TESTE_EV_30D(DROP=CHANNEL_CD);&lt;BR /&gt; MERGE SMS_30 (IN=A DROP=MOMENTO)&lt;BR /&gt; EMAIL_30 (IN=B DROP=MOMENTO)&lt;BR /&gt; TEST_30D_V3 (IN=C KEEP=X_ACCT_KEY MOMENTO);&lt;BR /&gt; BY X_ACCT_KEY;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 14:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301760#M63914</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2016-09-30T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Query with Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301771#M63918</link>
      <description>&lt;P&gt;No need to shout, code runs just as well in lower case with consistent identations&amp;nbsp;&lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://communities.sas.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 15:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sub-Query-with-Data-step/m-p/301771#M63918</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-30T15:20:04Z</dc:date>
    </item>
  </channel>
</rss>

