<?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: Conditionally Proc append in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641080#M191044</link>
    <description>&lt;P&gt;You're still using your macro. Make the code work WITHOUT(!!!!) ANY macro elements, before starting to make it dynamic.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 19 Apr 2020 12:14:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-19T12:14:54Z</dc:date>
    <item>
      <title>Conditionally Proc append or Insert</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641055#M191028</link>
      <description>&lt;P&gt;Assume I have two datasets. One dataset (details)&amp;nbsp;has five variables&amp;nbsp;namely Run_Id,Company_code,Datasource,Table_Name,Table_Count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Out of these 5 variables, first three variables get data from one program which we no need to worry. Now I've feed the data into last two variables Table_Name and Table_Count based on Run_ID by one program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've a program as below which will create three variables - Run_ID,Table_Name,Table_Count&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below program is creating a table called 'Insurance', but I'm not sure how to append/insert data into IFR.Details when Run_ID matches between the datasets Insurance and IFR.Details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run_ID in Insurance dataset is extract from other WORK dataset Status_tech.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc append below is not working correctly and I'm looking some help here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At beginning IFR.Details dataset will be like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="418"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="98"&gt;Company_code&lt;/TD&gt;
&lt;TD width="91"&gt;Datasource&lt;/TD&gt;
&lt;TD width="89"&gt;Table_name&lt;/TD&gt;
&lt;TD width="76"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;Database&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12346&lt;/TD&gt;
&lt;TD&gt;DEF&lt;/TD&gt;
&lt;TD&gt;Excel&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Insurance dataset will be like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="278"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="98"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="91"&gt;Table_name&lt;/TD&gt;
&lt;TD width="89"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;Insurance&lt;/TD&gt;
&lt;TD&gt;87&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need IFR.Details dataset which should looks like as below. I just have to feed the data to two variables from&amp;nbsp;Insurance dataset when Run_ID matcjes between Insurance and IFR.Details dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="418"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="98"&gt;Company_code&lt;/TD&gt;
&lt;TD width="91"&gt;Datasource&lt;/TD&gt;
&lt;TD width="89"&gt;Table_name&lt;/TD&gt;
&lt;TD width="76"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;Database&lt;/TD&gt;
&lt;TD&gt;Insurance&lt;/TD&gt;
&lt;TD&gt;87&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12346&lt;/TD&gt;
&lt;TD&gt;DEF&lt;/TD&gt;
&lt;TD&gt;Excel&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;options symbolgen mlogic mprint;

%MACRO STATUS_TECH_UPDATE(tab);
	%put &amp;amp;tab;
	proc sql;
		create table &amp;amp;tab as
			select 
				"&amp;amp;tab" as table_name
				,count(1) as table_count
				,B.run_id
			from IFR.&amp;amp;tab A, STATUS_TECH B
				where A.RUN_ID = B.RUN_ID;
	quit;&lt;BR /&gt;
/*append/insert data into IFR.Details when Run_ID matches between the datasets Insuarnce and IFR.Details.*/&lt;BR /&gt;/*below append is not working as excepted and I'm not sure how to append based on Run_ID*/
	proc append base=IFR.Details data=&amp;amp;tab(drop=run_id) force;
	run;
%MEND;

%STATUS_TECH_UPDATE(Insurance);&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 09:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641055#M191028</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T09:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641057#M191030</link>
      <description>&lt;P&gt;Remove all macro elements from your code, and run it with literally set datset names.&lt;/P&gt;
&lt;P&gt;Run the code in steps, read the log, and inspect the resulting dataset(s) after each individual step.&lt;/P&gt;
&lt;P&gt;Do not start to wrap your code into a macro before it is verified that it works.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 08:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641057#M191030</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-19T08:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641060#M191031</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At beginning IFR.Details dataset will be like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="418"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="98"&gt;Company_code&lt;/TD&gt;
&lt;TD width="91"&gt;Datasource&lt;/TD&gt;
&lt;TD width="89"&gt;Table_name&lt;/TD&gt;
&lt;TD width="76"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;Database&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12346&lt;/TD&gt;
&lt;TD&gt;DEF&lt;/TD&gt;
&lt;TD&gt;Excel&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Insurance dataset will be like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="278"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="98"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="91"&gt;Table_name&lt;/TD&gt;
&lt;TD width="89"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;Insurance&lt;/TD&gt;
&lt;TD&gt;87&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need IFR.Details dataset which should looks like as below. I just have to feed the data to two variables from&amp;nbsp;Insurance dataset when Run_ID matcjes between Insurance and IFR.Details dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="418"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Run_ID&lt;/TD&gt;
&lt;TD width="98"&gt;Company_code&lt;/TD&gt;
&lt;TD width="91"&gt;Datasource&lt;/TD&gt;
&lt;TD width="89"&gt;Table_name&lt;/TD&gt;
&lt;TD width="76"&gt;Table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;Database&lt;/TD&gt;
&lt;TD&gt;Insurance&lt;/TD&gt;
&lt;TD&gt;87&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12346&lt;/TD&gt;
&lt;TD&gt;DEF&lt;/TD&gt;
&lt;TD&gt;Excel&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 09:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641060#M191031</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T09:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641068#M191034</link>
      <description>&lt;P&gt;What you want is a simple update, not an append:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data details;
infile datalines truncover;
input Run_ID :$5. Company_code :$3. Datasource :$10. Table_name :$10. table_count;
datalines;
12345 ABC Database	 	 
12346 DEF Excel
;

data insurance;
input Run_ID :$5. Table_name :$10. Table_count;
datalines;
12345 Insurance 87
;

data want;
update
  details
  insurance
;
by run_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 10:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641068#M191034</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-19T10:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641077#M191041</link>
      <description>&lt;P&gt;I;m getting an error when I tried with the code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; IFR.details;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;update&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; IFR.details &amp;amp;tab;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; run_id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;21        + data IFR.details    update IFR.details INSURANCE;    by run_id;    run;

ERROR:  This table will not be replaced. This engine does not support the REPLACE option.&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;When I tried with code as below, I'm not seeing any values in table_name and table_count. I used this code inside the macro as I mentioned in the Initial post. Am I missing something or misplacement of proc SQL update?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;update&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; IFR.details as a&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; table_name=(select table_name from &amp;amp;tab as b &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.run_id=b.run_id),&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; table_count=(select table_count from &amp;amp;tab as b &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.run_id=b.run_id); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 12:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641077#M191041</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T12:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641078#M191042</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Used proc SQL update as mentioned below. Run_id is matching between the tables but still I'm not seeing any values under Table_name and Table_count fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;options symbolgen mlogic mprint;

%MACRO STATUS_TECH_UPDATE(tab);
	%put &amp;amp;tab;
	proc sql;
		create table &amp;amp;tab as
			select 
				"&amp;amp;tab" as table_name
				,count(1) as table_count
				,B.run_id
			from IFR.&amp;amp;tab A, STATUS_TECH B
				where A.RUN_ID = B.RUN_ID;
	quit;

   proc sql;
   update IFR.details as a
   set table_name=(select table_name from &amp;amp;tab as b where a.run_id=b.run_id),
   table_count=(select table_count from &amp;amp;tab as b where a.run_id=b.run_id);                     
   quit;

%MEND;

%STATUS_TECH_UPDATE(Insurance);&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 12:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641078#M191042</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T12:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641079#M191043</link>
      <description>&lt;P&gt;Please show details of the IFR library. A SAS library allows this kind of update.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 12:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641079#M191043</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-19T12:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641080#M191044</link>
      <description>&lt;P&gt;You're still using your macro. Make the code work WITHOUT(!!!!) ANY macro elements, before starting to make it dynamic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 12:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641080#M191044</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-19T12:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641081#M191045</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Per data it should update only one row in target table but log says 23 rows were updated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Log says&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;17        +            proc sql;    update IFR.details as a    set table_name=(select table_name from 
      INSURANCE as b where a.run_id=b.run_id),    table_count=(select table_count from 
      INSURANCE as b where

18        + a.run_id=b.run_id);
NOTE: 23 rows were updated in IFR.details&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 12:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641081#M191045</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T12:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641084#M191048</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I place the proc sql update outside the macro it is working but it is&lt;BR /&gt;not working if I wrap it inside the macro.&lt;BR /&gt;&lt;BR /&gt;I want to update the target table using a macro as the &amp;amp;tab macro variable&lt;BR /&gt;resolves to multiple table names which should run for each table one by one.&lt;BR /&gt;&lt;BR /&gt;Only proc sql update step which was inside the macro is not working, other&lt;BR /&gt;steps are running fine.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641084#M191048</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T13:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641086#M191050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I place the proc sql update outside the macro it is working but it is&lt;BR /&gt;not working if I wrap it inside the macro.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show us this working non-macro code.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641086#M191050</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-19T13:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641088#M191051</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I place the proc sql update outside the macro it is working but it is&lt;BR /&gt;not working if I wrap it inside the macro.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show us this working non-macro code.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe this time?&amp;nbsp;&lt;A href="https://en.wiktionary.org/wiki/third_time%27s_a_charm" target="_blank"&gt;https://en.wiktionary.org/wiki/third_time%27s_a_charm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641088#M191051</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T13:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641089#M191052</link>
      <description>&lt;P&gt;You need a WHERE clause on the UPDATE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;update TABLE set VARIABLE=EXPRESSION where CONDITION;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641089#M191052</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T13:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641090#M191053</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code works fine outside the macro but not within the macro. Please see the comment before second step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did added WHERE before update Statement as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;mentioned but still no luck if I run it within the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
select "'"||compress(RUN_ID)||"'" into :mac separated by ","
from ifr.details;
quit;

/*If I run with one table called INSURANCE it's working*/
/*But in real life I will be creating macro variable called 'tab' which will holds the values of table names and I want to to run the proc sql update for each table*/
proc sql;
update ifr.details (where = (RUN_ID IN (&amp;amp;mac.)))  as a
set table_name=(select table_name from INSURANCE as b where a.run_id=b.run_id),
table_count=(select table_count from INSURANCE as b where a.run_id=b.run_id);                     
quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641090#M191053</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T13:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641091#M191054</link>
      <description>&lt;P&gt;That code is updating ALL table name values. Show an example of the code that runs for only ONE table name.&amp;nbsp; Just pick one of the table name values and put it in as a quoted string into the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you get it working then replace the literal name with a macro variable reference.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641091#M191054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T13:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641093#M191056</link>
      <description>Could you please help me understand how to put the table name in quoted&lt;BR /&gt;string?&lt;BR /&gt;&lt;BR /&gt;In my code from previous post, INSURANCE is one of the table name value.&lt;BR /&gt;</description>
      <pubDate>Sun, 19 Apr 2020 13:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641093#M191056</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T13:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641095#M191058</link>
      <description>&lt;P&gt;Don't you want to update the values of RUN_ID that are in INSURANCE? Not all of the values or RUN_ID.&lt;/P&gt;
&lt;P&gt;Also don't remove leading or embedded spaces from RUN_ID, that could lead to mismatches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure the impact of trying to use a WHERE= clause on the target of an UPDATE statement.&amp;nbsp; What would that even mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select quote(trim(RUN_ID)) into :mac separated by ' '
  from INSURANCE
;
quit;

proc sql;
update ifr.details a
  set table_name=(select table_name from INSURANCE b where a.run_id=b.run_id)
    , table_count=(select table_count from INSURANCE b where a.run_id=b.run_id)
  where a.run_id in (&amp;amp;mac)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can eliminate the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update ifr.details a
  set table_name=(select table_name from INSURANCE b where a.run_id=b.run_id)
    , table_count=(select table_count from INSURANCE b where a.run_id=b.run_id)
  where a.run_id in (select b.run_id from INSURANCE b)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can try replacing INSURANCE with a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tab=INSURANCE;
proc sql;
update ifr.details a
  set table_name=(select table_name from &amp;amp;tab b where a.run_id=b.run_id)
    , table_count=(select table_count from &amp;amp;tab b where a.run_id=b.run_id)
  where a.run_id in (select b.run_id from &amp;amp;tab b)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that still works then try wrapping it in a macro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 14:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641095#M191058</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T14:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641098#M191061</link>
      <description>&lt;P&gt;Corrected SQL, updates only one observation with my previous example data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update details a
  set
    table_name = (select table_name from insurance b where a.run_id = b.run_id),
    table_count = (select table_count from insurance b where a.run_id = b.run_id)
  where a.run_id in (select run_id from insurance)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To put that into a macro, so you can update from a series of tables:&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),
    table_count = (select table_count from &amp;amp;table. b where a.run_id = b.run_id)
  where a.run_id in (select run_id from &amp;amp;table.)
;
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now call that for every table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
input tablename $32.;
call execute(cats('%nrstr(%update(',tablename,'))'));
datalines;
insurance
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Complete code with data, tested on SAS UE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data details;
infile datalines truncover;
input Run_ID :$5. Company_code :$3. Datasource :$10. Table_name :$10. table_count;
datalines;
12345 ABC Database	 	 
12346 DEF Excel
;

data insurance;
input Run_ID :$5. Table_name :$10. Table_count;
datalines;
12345 Insurance 87
;

%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 run_id from &amp;amp;table.)
;
quit;
%mend;

data _null_;
input tablename $32.;
call execute(cats('%nrstr(%update(',tablename,'))'));
datalines;
insurance
;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 14:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641098#M191061</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-19T14:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641100#M191063</link>
      <description>Thanks a ton!&lt;BR /&gt;Can we also dynamically delete the WORK datasets which will be created&lt;BR /&gt;while the macro executes?&lt;BR /&gt;</description>
      <pubDate>Sun, 19 Apr 2020 14:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641100#M191063</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T14:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Proc append</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641101#M191064</link>
      <description>&lt;P&gt;You can use PROC DELETE. Or in SQL you can use DROP TABLE statement.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 14:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Proc-append-or-Insert/m-p/641101#M191064</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T14:56:19Z</dc:date>
    </item>
  </channel>
</rss>

