<?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: Creating Flags when condition is met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504570#M135050</link>
    <description>&lt;P&gt;Thanks for correcting me. The below code is working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data account_new;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;if _n_ = 0 then set All_account;&lt;BR /&gt;dcl hash h1(dataset: "subacc1 (rename = (account_no = AccountNo )");&lt;BR /&gt;h1.definekey("AccountNo");&lt;BR /&gt;h1.definedone();&lt;BR /&gt;dcl hash h2(dataset: "subacc2 (rename = (account_no = AccountNo )");&lt;BR /&gt;h2.definekey("AccountNo");&lt;BR /&gt;h2.definedone();&lt;BR /&gt;dcl hash h3(dataset: "subacc3 (rename = (account_no = AccountNo )");&lt;BR /&gt;h3.definekey("AccountNo");&lt;BR /&gt;h3.definedone();&lt;BR /&gt;dcl hash h4(dataset: "subacc4 (rename = (account_no = AccountNo )");&lt;BR /&gt;h4.definekey("AccountNo");&lt;BR /&gt;h4.definedone();&lt;BR /&gt;end;&lt;BR /&gt;set All_account;&lt;BR /&gt;if h1.find() = 0 then subacc1 =1;&lt;BR /&gt;else subacc1 = 0 ;&lt;BR /&gt;if h2.find() = 0 then subacc2 =1;&lt;BR /&gt;else subacc2 = 0 ;&lt;BR /&gt;if h3.find() = 0 then subacc3 =1;&lt;BR /&gt;else subacc3 = 0 ;&lt;BR /&gt;if h4.find() = 0 then subacc4 =1;&lt;BR /&gt;else subacc4 = 0 ;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Oct 2018 02:23:21 GMT</pubDate>
    <dc:creator>Suja</dc:creator>
    <dc:date>2018-10-16T02:23:21Z</dc:date>
    <item>
      <title>Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504545#M135032</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My below query is taking around 40 minutes to run for 1million records in All_account. my subacc1 has 80 records, subacc2 has 47 records, subacc3 has 68 records and subacc4 has 75 records.&amp;nbsp;I want to reduce the processing time. Any help would be much appreciated. Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table account_new as&lt;BR /&gt;select a.*,&lt;BR /&gt;(case when exists (select 1 from subacc1 b where a.AccountNo = b.account_no)&lt;BR /&gt;then 1 else 0&lt;BR /&gt;end) as subacc1,&lt;BR /&gt;(case when exists (select 1 from subacc2 c where a.AccountNo = c.account_no)&lt;BR /&gt;then 1 else 0&lt;BR /&gt;end) as subacc2,&lt;BR /&gt;(case when exists (select 1 from subacc3 d where a.AccountNo = d.account_no)&lt;BR /&gt;then 1 else 0&lt;BR /&gt;end) as subacc3,&lt;BR /&gt;(case when exists (select 1 from subacc4 e where a.AccountNo = e.account_no)&lt;BR /&gt;then 1 else 0&lt;BR /&gt;end) as subacc4&lt;BR /&gt;from All_account a;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 23:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504545#M135032</guid>
      <dc:creator>Suja</dc:creator>
      <dc:date>2018-10-15T23:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504556#M135040</link>
      <description>&lt;P&gt;this is good case for using hash technique. I made data using Sashelp.class so that you can try out. here we are making flags based on name present in particular dataset&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_female;
 set sashelp.class(where=(sex='F'));
 run;
 
  data class_male;
 set sashelp.class(where=(sex='M'));
 run;
 
 
   data want;
if _n_=1 then do;
if _n_ = 0 then set sashelp.class;
dcl hash h1(dataset: 'class_female');
 h1.definekey("Name");
 h1.definedone();
 dcl hash h2(dataset: 'class_male');
 h2.definekey("Name");
 h2.definedone();
 end;
 set sashelp.class;
 call missing(female_flag);
 if h1.find() = 0 then female_flag =1;
 else female_flag = 0 ;
 if h2.find() = 0 then male_flag =1;
 else male_flag = 0 ;
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 01:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504556#M135040</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-10-16T01:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504558#M135041</link>
      <description>&lt;P&gt;Thanks kiranv. I think I can't use the hash table in one dataset like your code. Because I'm joining with four different datasets.&lt;/P&gt;&lt;P&gt;I have used the hash table logic but calling the macro 4 times as below. Please let me know if there is any better solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro hash_macro (hash_table, in_table, out_table, keyvar, renamevar);&lt;/P&gt;&lt;P&gt;data &amp;amp;out_table. (drop=&amp;amp;renamevar.);&lt;BR /&gt;set &amp;amp;in_table.;&lt;BR /&gt;if _n_ = 0 then set &amp;amp;hash_table.;&lt;BR /&gt;if _n_ = 1 then do;&lt;BR /&gt;declare hash ht (dataset: "&amp;amp;hash_table. (rename = (&amp;amp;renamevar. = &amp;amp;keyvar. ))",&lt;BR /&gt;ordered: "A");&lt;BR /&gt;ht.definekey ("&amp;amp;keyvar.");&lt;BR /&gt;ht.definedata ("&amp;amp;keyvar.");&lt;BR /&gt;ht.definedone ( );&lt;BR /&gt;end;&lt;BR /&gt;if ht.find() = 0 then do; &amp;amp;hash_table. = 1; output; end;&lt;BR /&gt;else do; &amp;amp;hash_table. = 0; output; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;BR /&gt;/* call hash_macro for account table*/&lt;BR /&gt;%hash_macro(subacc1, all_account, account1, AccountNo, account_no);&lt;BR /&gt;%hash_macro(subacc2, account1, account2, AccountNo, account_no);&lt;BR /&gt;%hash_macro(subacc3, account2, account3, AccountNo, account_no);&lt;BR /&gt;%hash_macro(subacc4, account3, account_new, AccountNo, account_no);&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 01:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504558#M135041</guid>
      <dc:creator>Suja</dc:creator>
      <dc:date>2018-10-16T01:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504561#M135044</link>
      <description>&lt;P&gt;if you see, I am using 2 datasets(lookup/small datasets) and you can use 4. you are creating four tables in your&amp;nbsp;macro code, which is unlike your first table/intial code.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 01:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504561#M135044</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-10-16T01:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504564#M135047</link>
      <description>&lt;P&gt;I don't think you need 2 hash tables nor is hash the best solution?I'm not certain but can't&amp;nbsp; confirm until I pplay around&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be possible to provide some representative samples and the required output for us to work ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me admit, I'm too lazy to assume, simulate to be totally honest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 02:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504564#M135047</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-16T02:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504570#M135050</link>
      <description>&lt;P&gt;Thanks for correcting me. The below code is working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data account_new;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;if _n_ = 0 then set All_account;&lt;BR /&gt;dcl hash h1(dataset: "subacc1 (rename = (account_no = AccountNo )");&lt;BR /&gt;h1.definekey("AccountNo");&lt;BR /&gt;h1.definedone();&lt;BR /&gt;dcl hash h2(dataset: "subacc2 (rename = (account_no = AccountNo )");&lt;BR /&gt;h2.definekey("AccountNo");&lt;BR /&gt;h2.definedone();&lt;BR /&gt;dcl hash h3(dataset: "subacc3 (rename = (account_no = AccountNo )");&lt;BR /&gt;h3.definekey("AccountNo");&lt;BR /&gt;h3.definedone();&lt;BR /&gt;dcl hash h4(dataset: "subacc4 (rename = (account_no = AccountNo )");&lt;BR /&gt;h4.definekey("AccountNo");&lt;BR /&gt;h4.definedone();&lt;BR /&gt;end;&lt;BR /&gt;set All_account;&lt;BR /&gt;if h1.find() = 0 then subacc1 =1;&lt;BR /&gt;else subacc1 = 0 ;&lt;BR /&gt;if h2.find() = 0 then subacc2 =1;&lt;BR /&gt;else subacc2 = 0 ;&lt;BR /&gt;if h3.find() = 0 then subacc3 =1;&lt;BR /&gt;else subacc3 = 0 ;&lt;BR /&gt;if h4.find() = 0 then subacc4 =1;&lt;BR /&gt;else subacc4 = 0 ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 02:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504570#M135050</guid>
      <dc:creator>Suja</dc:creator>
      <dc:date>2018-10-16T02:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504574#M135051</link>
      <description>&lt;P&gt;Just curious to know, how much time the hash solution took&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 02:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504574#M135051</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-10-16T02:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504575#M135052</link>
      <description>&lt;P&gt;My old query took 47 minutes and hash table took less than a minute (3.16 seconds).&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 03:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-when-condition-is-met/m-p/504575#M135052</guid>
      <dc:creator>Suja</dc:creator>
      <dc:date>2018-10-16T03:07:00Z</dc:date>
    </item>
  </channel>
</rss>

