<?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: Combine data step and proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498950#M132694</link>
    <description>&lt;P&gt;Those two SQL's has a common table&amp;nbsp;session.incomm and it made me to believe to combine into one.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Sep 2018 05:00:47 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2018-09-26T05:00:47Z</dc:date>
    <item>
      <title>Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498929#M132679</link>
      <description>&lt;P&gt;Could &amp;nbsp;someone of you guide me to combine the below data step and proc sql in one step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table todocomm as
select 	a.ExternalIdentifier as commnr,
		a.identifier as communicationID,
   		a.communicationtypeid,
		a.communicationdescriptionid,
		a.inboxforcommunicationID,
   		a.isincoming as incoming,
		a.policyid,
   		a.policyinstanceid,
   		a.tscommunicationcreated,
   		a.datetobecompleted,
   		a.createdbylogonuserid,
   		b.externalidentifier as polisnr
   from db2qiso.rpcommunication a, db2qiso.rppolicy b
   where a.policyid=b.identifier;
quit;

proc sql;
	create table todocomm2 as
	select a.*, b.tsevent, b.communicationstatusid
	from todocomm a, db2qiso.rpcommunicationevent b
	where a.communicationID=b.communicationid
	and int(sum(tsevent,0)/86400) &amp;lt; &amp;amp;einddat;
quit;
proc sort data=todocomm2 out=todocomm2; by polisnr commnr tsevent; run;

data todocomm3;
  set todocomm2;
  by polisnr commnr tsevent;
  if last.commnr; 
run;

data todocomm4 (drop=tsevent communicationstatusid);
  set todocomm3;
  if communicationstatusid not in ('00000000003' '00000000004');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 02:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498929#M132679</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-26T02:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498937#M132684</link>
      <description>&lt;P&gt;Unless performance is an issue, I would keep 2 steps.&lt;/P&gt;
&lt;P&gt;This should be equivalent to what you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table todocomm as
select a.EXTERNALIDENTIFIER        as COMMNR  
      ,a.IDENTIFIER                as COMMUNICATIONID  
      ,a.COMMUNICATIONTYPEID  
      ,a.COMMUNICATIONDESCRIPTIONID  
      ,a.INBOXFORCOMMUNICATIONID  
      ,a.ISINCOMING                as INCOMING  
      ,a.POLICYID  
      ,a.POLICYINSTANCEID  
      ,a.TSCOMMUNICATIONCREATED  
      ,a.DATETOBECOMPLETED  
      ,a.CREATEDBYLOGONUSERID  
      ,b.EXTERNALIDENTIFIER        as POLISNR  
      ,c.TSEVENT
      ,c.COMMUNICATIONSTATUSID
   from db2qiso.RPCOMMUNICATION      a
          inner join
        db2qiso.RPPOLICY             b
          on a.POLICYID = b.IDENTIFIER
          inner join
        db2qiso.RPCOMMUNICATIONEVENT c
          on  a.IDENTIFIER = c.COMMUNICATIONID
          and int(sum(c.TSEVENT,0)/86400) &amp;lt; &amp;amp;einddat.
  order by POLISNR, COMMNR, TSEVENT; 
quit;

data TODOCOMM2;
  set TODOCOMM;
  by POLISNR COMMNR TSEVENT;
  if last.COMMNR; 
  if COMMUNICATIONSTATUSID not in ('00000000003' '00000000004');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If this query is passed to DB2, too much data&amp;nbsp;might be sent to SAS as the clause&amp;nbsp;&lt;FONT face="courier new,courier"&gt;int(sum(c.TSEVENT,0)/86400) &amp;lt; &amp;amp;einddat.&lt;/FONT&gt; might not be sent to DB2. Check this point by using option&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sastrace = ',,,d'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. SQL has no easy to to code the &lt;FONT face="courier new,courier"&gt;last.&lt;/FONT&gt; operator, and the data step has no easy way to merge and sort by multiple variables. Hence my preference to keep 2 steps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 03:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498937#M132684</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-26T03:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498938#M132685</link>
      <description>&lt;P&gt;The last. syntax is not (very easily) available in SQL, so I'd recommend keeping it as two steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table todocomm as
select 	a.ExternalIdentifier as commnr,
		a.identifier as communicationID,
   		a.communicationtypeid,
		a.communicationdescriptionid,
		a.inboxforcommunicationID,
   		a.isincoming as incoming,
		a.policyid,
   		a.policyinstanceid,
   		a.tscommunicationcreated,
   		a.datetobecompleted,
   		a.createdbylogonuserid,
   		b.externalidentifier as polisnr,
        c.tsevent, 
        c.communicationstatusid
   from db2qiso.rpcommunication as a
  inner join db2qiso.rppolicy as b
     on a.policyid=b.identifier
  inner join db2qiso.rpcommunicationevent as c
     on a.communicationID = c.communicationid
    and int(sum(c.tsevent, 0) / 86400) &amp;lt; &amp;amp;einddat
  order by polisnr,
           commnr,
           c.tsevent;
quit;

data todocomm3;
  set todocomm;
  by polisnr commnr;
  if last.commnr; 
  if communicationstatusid not in ('00000000003' '00000000004');
drop tsevent communicationstatusid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 03:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498938#M132685</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-09-26T03:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498948#M132692</link>
      <description>&lt;P&gt;Got it. How will you combine these two SQL now?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Inbox for communication */
create table incomm4 as
(
select distinct b.identifier as inboxforcommunicationID, b.name as afdeling
from session.incomm a left join qis.rpinboxforcommunication b
on a.inboxforcommunicationID=b.identifier
where b.identifier in ('00000000001','10000000000','10000000001','10000000003')
);
/* createur */
create table incomm5 as
select distinct createdbylogonuserid, left(trim(lastname))||' '||left(trim(firstname)) as creator, creator_duser
(
select 	b.identifier as createdbylogonuserid,
		b.externalidentifier as creator_duser,	
		b.lastname,b.firstname
from session.incomm a  left join qis.rplogonuser b
on a.createdbylogonuserid=b.identifier
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 04:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498948#M132692</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-26T04:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498949#M132693</link>
      <description>&lt;P&gt;1. This&amp;nbsp;is a&amp;nbsp;different question, start a new thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You can't combine these as shown. They don't depend on each other and just create 2 different tables with different columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 04:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498949#M132693</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-26T04:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data step and proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498950#M132694</link>
      <description>&lt;P&gt;Those two SQL's has a common table&amp;nbsp;session.incomm and it made me to believe to combine into one.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 05:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-step-and-proc-sql/m-p/498950#M132694</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-26T05:00:47Z</dc:date>
    </item>
  </channel>
</rss>

