<?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 SAS _iorc_  delete (remove) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499815#M133040</link>
    <description>&lt;P&gt;Is there a way to delete record in 'master' table if the record is not available in 'transact' table? For below code, id 01 should be deleted as 01 is not available in transact table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried this but not work.&lt;/P&gt;&lt;P&gt;if _iorc_ eq 1 then do;&lt;BR /&gt;_reason_change_ = 'Remove';&lt;BR /&gt;remove;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**program start**/&lt;/P&gt;&lt;P&gt;data master;&lt;BR /&gt;input id $ name $ gender $ weight;&lt;BR /&gt;datalines;&lt;BR /&gt;01 Perry M 165&lt;BR /&gt;02 Miller M 145&lt;BR /&gt;03 Davis F 127&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data transact;&lt;BR /&gt;input id $ name $ gender $ weight;&lt;BR /&gt;datalines;&lt;BR /&gt;02 Miller . 160&lt;BR /&gt;03 Bush . 157&lt;BR /&gt;05 Elliot F 125&lt;BR /&gt;02 . M 170&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=master; BY id; RUN;&lt;BR /&gt;proc sort data=transact; BY id; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc datasets lib=work;&lt;BR /&gt;audit master;&lt;BR /&gt;initiate;&lt;BR /&gt;user_var _reason_change_ $30;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data master;&lt;BR /&gt;modify master transact;&lt;BR /&gt;by id;&lt;BR /&gt;if _iorc_ eq 0 then do;&lt;BR /&gt;_reason_change_ = 'Update';&lt;BR /&gt;replace;&lt;BR /&gt;end;&lt;BR /&gt;else if _iorc_ eq 1230013 then do;&lt;BR /&gt;_reason_change_ = 'new';&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;errmsg=IORCMSG();&lt;BR /&gt;putlog 'NOTE: ' errmsg= _iorc_=;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data auditchk;&lt;BR /&gt;set Master(type=audit);&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 09:15:21 GMT</pubDate>
    <dc:creator>scb</dc:creator>
    <dc:date>2018-09-28T09:15:21Z</dc:date>
    <item>
      <title>SAS _iorc_  delete (remove)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499815#M133040</link>
      <description>&lt;P&gt;Is there a way to delete record in 'master' table if the record is not available in 'transact' table? For below code, id 01 should be deleted as 01 is not available in transact table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried this but not work.&lt;/P&gt;&lt;P&gt;if _iorc_ eq 1 then do;&lt;BR /&gt;_reason_change_ = 'Remove';&lt;BR /&gt;remove;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**program start**/&lt;/P&gt;&lt;P&gt;data master;&lt;BR /&gt;input id $ name $ gender $ weight;&lt;BR /&gt;datalines;&lt;BR /&gt;01 Perry M 165&lt;BR /&gt;02 Miller M 145&lt;BR /&gt;03 Davis F 127&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data transact;&lt;BR /&gt;input id $ name $ gender $ weight;&lt;BR /&gt;datalines;&lt;BR /&gt;02 Miller . 160&lt;BR /&gt;03 Bush . 157&lt;BR /&gt;05 Elliot F 125&lt;BR /&gt;02 . M 170&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=master; BY id; RUN;&lt;BR /&gt;proc sort data=transact; BY id; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc datasets lib=work;&lt;BR /&gt;audit master;&lt;BR /&gt;initiate;&lt;BR /&gt;user_var _reason_change_ $30;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data master;&lt;BR /&gt;modify master transact;&lt;BR /&gt;by id;&lt;BR /&gt;if _iorc_ eq 0 then do;&lt;BR /&gt;_reason_change_ = 'Update';&lt;BR /&gt;replace;&lt;BR /&gt;end;&lt;BR /&gt;else if _iorc_ eq 1230013 then do;&lt;BR /&gt;_reason_change_ = 'new';&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;errmsg=IORCMSG();&lt;BR /&gt;putlog 'NOTE: ' errmsg= _iorc_=;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data auditchk;&lt;BR /&gt;set Master(type=audit);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 09:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499815#M133040</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2018-09-28T09:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS _iorc_  delete (remove)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499841#M133046</link>
      <description>&lt;P&gt;No, not the way you do it. When you use&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;modify master transact; 
by id&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the records in the master dataset are read using dynamic WHERE clauses, and the records with IDs that are not in TRANSACT are never read from MASTER.&lt;/P&gt;&lt;P&gt;You can do it by adding an extra step, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
  modify master transact;
  by id;
  if _iorc_ eq 0 then do;
    _reason_change_ = 'Update';
    replace;
    end;
  else if _iorc_ eq 1230013 then do;
    _reason_change_ = 'new';
	_error_=0; 
    output;
    end;
  else do;
    errmsg=IORCMSG();
    putlog 'NOTE: ' errmsg= _iorc_=;
    end;
run;
proc sql;&lt;BR /&gt;  create index id on transact(id); &lt;BR /&gt;quit; 
&lt;BR /&gt;data master;
  modify master;
  set transact key=id;
  if _iorc_ then do;
    _reason_change_='Delete';
	_error_=0;
	remove;
	end;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But your _reason_change_ will not get written to the audit table, as it is written to the new record, not the old, and there is no new record when you remove.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 11:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499841#M133046</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-09-28T11:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS _iorc_  delete (remove)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499843#M133047</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you can modify your master tabel a little bit maybe following code will do the job for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**program start**/

data master;
input id $ name $ gender $ weight;
_A_=.; /* additiona variable which marks if a given 
          record from master apeared in transact
       */
datalines;
01 Perry M 165
02 Miller M 145
03 Davis F 127
;
run;

data transact;
input id $ name $ gender $ weight;
datalines;
02 Miller . 160
03 Bush . 157
05 Elliot F 125
02 . M 170
;
run;

proc sort data=master; BY id; RUN;
proc sort data=transact; BY id; RUN;

proc datasets lib=work;
audit master;
initiate;
user_var _reason_change_ $30;
quit;

/* before modyfication set marker's value */ 
%let marker=%sysfunc(datetime());

data master;
modify master transact;
by id;
put "*" _N_=;
if _iorc_ eq 0 then do;
_reason_change_ = 'Update';
_A_ = symget('marker'); /* refresh value of marker variable */
replace;
end;
else if _iorc_ eq 1230013 then do;
_reason_change_ = 'New';
_A_ = symget('marker'); /* refresh value of marker variable */
output;
end;
else do;
errmsg=IORCMSG();
_A_ = symget('marker'); /* refresh value of marker variable */
putlog 'NOTE: ' errmsg= _iorc_=;
end;
run;

data master;
modify master;
/* if value of marker variable is not equal to marker's value
   then given ID in master wasn't in transact
*/
if _A_ NE symget('marker') then do; _reason_change_ = 'Remove'; remove; end;
run;

data auditchk;
set Master(type=audit);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 11:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-iorc-delete-remove/m-p/499843#M133047</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2018-09-28T11:20:33Z</dc:date>
    </item>
  </channel>
</rss>

