<?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: Update base table for every iteration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/641824#M191370</link>
    <description>&lt;P&gt;Small adjustments to match on company_code as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro update(table);
proc sql;
update details a
  set
    table_name = (select table_name from &amp;amp;table. b where a.run_id=b.run_id and a.company_code = b.company_code),
    table_count = (select table_count from &amp;amp;table. b where a.run_id=b.run_id and a.company_code = b.company_code)
  where cats(a.run_id,a.company_code) in (select cats(b.run_id,b.company_code) from &amp;amp;table. as b)
;
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Apr 2020 06:33:22 GMT</pubDate>
    <dc:creator>unison</dc:creator>
    <dc:date>2020-04-22T06:33:22Z</dc:date>
    <item>
      <title>Update base table for every iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/641804#M191358</link>
      <description>&lt;P&gt;I've the data and code as follows. I want to update the base table for every Iteration, but it seems there is an issue while updating the base table with my code.Instead of updating the base table with every Iteration, it is replacing the results in the base table for matching observations. Request your help here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code which I have is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data details;
infile datalines truncover;
input Run_ID :5. Company_code :$3. Datasource :$10. Table_name :$10. table_count : 2.;
datalines;
12345 ABC Database   
12345 ABD Database   
12345 ABE Database   
12345 ABF Database   
12346 DEF Excel
;

data insurance;
input Company_code :$5. Table_name :$10. Table_count :2. Run_ID :5.;
datalines;
ABC Insurance 87 12345
;

data insurancf;
input Company_code :$5. Table_name :$10. Table_count :2. Run_ID :5.;
datalines;
ABD Insurancf 88 12345
;

data insurancg;
input Company_code :$5. Table_name :$10. Table_count :2. Run_ID :5.;
datalines;
ABE Insurancg 89 12345
;

data insuranch;
input Company_code :$5. Table_name :$10. Table_count :2. Run_ID :5.;
datalines;
DEF Insuranch 90 12346
;

%macro update(table);
proc sql;
update details a
  set
    table_name = (select table_name from &amp;amp;table. b where a.run_id=b.run_id),
    table_count = (select table_count from &amp;amp;table. b where a.run_id=b.run_id)
  where a.run_id in (select b.run_id from &amp;amp;table. as b)
;
quit;
%mend;

%let filelist=insurance insurancf insurancg insuranch ;


data _null_;
  length tablename $32 ;
  do i=1 to countw("&amp;amp;filelist",' ');
    tablename=scan("&amp;amp;filelist",i,' ');
    call execute(cats('%nrstr(%update(',tablename,'))'));
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Result which I got is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run_ID&amp;nbsp;Company_code&amp;nbsp;Datasource&amp;nbsp;Table_name&amp;nbsp;table_count&lt;BR /&gt;12345&amp;nbsp;ABC&amp;nbsp;Database&amp;nbsp;Insurancg&amp;nbsp;89&lt;BR /&gt;12345&amp;nbsp;ABD&amp;nbsp;Database&amp;nbsp;Insurancg&amp;nbsp;89&lt;BR /&gt;12345&amp;nbsp;ABE&amp;nbsp;Database&amp;nbsp;Insurancg&amp;nbsp;89&lt;BR /&gt;12345&amp;nbsp;ABF&amp;nbsp;Database&amp;nbsp;Insurancg&amp;nbsp;89&lt;BR /&gt;12346&amp;nbsp;DEF&amp;nbsp;Excel&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Insuranch&amp;nbsp;90&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run_ID&amp;nbsp;Company_code&amp;nbsp;Datasource&amp;nbsp;Table_name&amp;nbsp;table_count&lt;BR /&gt;12345&amp;nbsp;ABC&amp;nbsp;Database&amp;nbsp;Insurance&amp;nbsp;87&lt;BR /&gt;12345&amp;nbsp;ABD&amp;nbsp;Database&amp;nbsp;Insurancf&amp;nbsp;88&lt;BR /&gt;12345&amp;nbsp;ABE&amp;nbsp;Database&amp;nbsp;Insurancg&amp;nbsp;89&lt;BR /&gt;12345&amp;nbsp;ABF&amp;nbsp;Database&amp;nbsp;&amp;nbsp;&lt;BR /&gt;12346&amp;nbsp;DEF&amp;nbsp;Excel&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Insuranch&amp;nbsp;90&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 03:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/641804#M191358</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-22T03:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Update base table for every iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/641824#M191370</link>
      <description>&lt;P&gt;Small adjustments to match on company_code as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro update(table);
proc sql;
update details a
  set
    table_name = (select table_name from &amp;amp;table. b where a.run_id=b.run_id and a.company_code = b.company_code),
    table_count = (select table_count from &amp;amp;table. b where a.run_id=b.run_id and a.company_code = b.company_code)
  where cats(a.run_id,a.company_code) in (select cats(b.run_id,b.company_code) from &amp;amp;table. as b)
;
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 06:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/641824#M191370</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-04-22T06:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Update base table for every iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/642670#M191767</link>
      <description>Do you want a missing table_name and table_count because none of the 'insurance' tables had run_id=12345 and company_code="ABF" ?&lt;BR /&gt;&lt;BR /&gt;If you were to process only one 'insurance' table should all the other rows of details be set to have missing values for their run_id and company_code ?&lt;BR /&gt;&lt;BR /&gt;In other words, should the table names and counts in details be set to missing when their runs and companies don't match the 'set' of tables names in the in the filelist?  What should happen if a filelisted table contains a new run/company combination ?</description>
      <pubDate>Fri, 24 Apr 2020 16:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-base-table-for-every-iteration/m-p/642670#M191767</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-24T16:52:08Z</dc:date>
    </item>
  </channel>
</rss>

