<?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: Optimization in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584171#M166319</link>
    <description>&lt;P&gt;Let's dissect your first step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INSURANCE_CASHFLOW_updated2 (drop=ISSUE_MONTH_old);
set INSURANCE_CASHFLOW (where=(REPORTING_CAUSE="A"));
length ISSUE_MONTH $72.; /* why are you wasting 65 empty bytes when you only store 7 bytes in the string? */
ISSUE_MONTH_old=put(ISSUE_DT,yymmn6.);
/* Read the documentation, and you will see that the "n" in the format stands for "no delimiter" */
/* Use yymmd7. in the next statement (d = dash) */
ISSUE_MONTH=cats(substr(ISSUE_MONTH_old,1,4),"-",substr(ISSUE_MONTH_old,5));
/* should be: */
ISSUE_MONTH = put(ISSUE_DT,yymmd7.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you only need this new variable for joining, so you can move that into the "on" clause in the SQL.&lt;/P&gt;
&lt;P&gt;Let's take a look at your third step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp_final (drop=ISSUE_MONTH INITIAL_RECOGNITION_DT); 
set temp3;
INSURANCE_CONTRACT_GROUP_ID=compress(cats(INSURANCE_CONTRACT_GROUP_ID,put(ISSUE_DT,date9.),put(INITIAL_RECOGNITION_DT,date9.)),.);
/* compress() expects a character value as its second argument, so the numerical missing value is wrong here */
/* if you want to get rid of dots caused by missing numerical values, use '.' as second argument */
/* This can be moved into the SQL also */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Creation of the new variable can also be moved into the SQL.&lt;/P&gt;
&lt;P&gt;So I propose to try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp_final as
select
  a.*,
  b.INITIAL_RECOGNITION_DT,
  compress(cats(a.INSURANCE_CONTRACT_GROUP_ID,put(a.ISSUE_DT,date9.),put(b.INITIAL_RECOGNITION_DT,date9.)),'.')
  as INSURANCE_CONTRACT_GROUP_ID
from INSURANCE_CASHFLOW as a
left join ADP_OUTPUT_NON_LIFE as b
on
  a.REPORTING_DT = b.REPORTING_DT and
  a.ENTITY_ID = b.UNIT and
  put(a.ISSUE_DT,yymmd7.) = b.ISSUE_MONTH
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS this code is of course untested, for lack of usable test data.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2019 11:24:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-08-27T11:24:02Z</dc:date>
    <item>
      <title>Optimization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584137#M166306</link>
      <description />
      <pubDate>Wed, 28 Aug 2019 11:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584137#M166306</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T11:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Optimization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584171#M166319</link>
      <description>&lt;P&gt;Let's dissect your first step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INSURANCE_CASHFLOW_updated2 (drop=ISSUE_MONTH_old);
set INSURANCE_CASHFLOW (where=(REPORTING_CAUSE="A"));
length ISSUE_MONTH $72.; /* why are you wasting 65 empty bytes when you only store 7 bytes in the string? */
ISSUE_MONTH_old=put(ISSUE_DT,yymmn6.);
/* Read the documentation, and you will see that the "n" in the format stands for "no delimiter" */
/* Use yymmd7. in the next statement (d = dash) */
ISSUE_MONTH=cats(substr(ISSUE_MONTH_old,1,4),"-",substr(ISSUE_MONTH_old,5));
/* should be: */
ISSUE_MONTH = put(ISSUE_DT,yymmd7.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you only need this new variable for joining, so you can move that into the "on" clause in the SQL.&lt;/P&gt;
&lt;P&gt;Let's take a look at your third step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp_final (drop=ISSUE_MONTH INITIAL_RECOGNITION_DT); 
set temp3;
INSURANCE_CONTRACT_GROUP_ID=compress(cats(INSURANCE_CONTRACT_GROUP_ID,put(ISSUE_DT,date9.),put(INITIAL_RECOGNITION_DT,date9.)),.);
/* compress() expects a character value as its second argument, so the numerical missing value is wrong here */
/* if you want to get rid of dots caused by missing numerical values, use '.' as second argument */
/* This can be moved into the SQL also */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Creation of the new variable can also be moved into the SQL.&lt;/P&gt;
&lt;P&gt;So I propose to try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp_final as
select
  a.*,
  b.INITIAL_RECOGNITION_DT,
  compress(cats(a.INSURANCE_CONTRACT_GROUP_ID,put(a.ISSUE_DT,date9.),put(b.INITIAL_RECOGNITION_DT,date9.)),'.')
  as INSURANCE_CONTRACT_GROUP_ID
from INSURANCE_CASHFLOW as a
left join ADP_OUTPUT_NON_LIFE as b
on
  a.REPORTING_DT = b.REPORTING_DT and
  a.ENTITY_ID = b.UNIT and
  put(a.ISSUE_DT,yymmd7.) = b.ISSUE_MONTH
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS this code is of course untested, for lack of usable test data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 11:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584171#M166319</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-27T11:24:02Z</dc:date>
    </item>
  </channel>
</rss>

