<?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 Data Step with Modifiy Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806755#M317920</link>
    <description>&lt;P&gt;&amp;nbsp;Hello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This Knowledge Base entry shows examples for using the "modify" statement:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/24/678.html" target="_self"&gt;https://support.sas.com/kb/24/678.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding example 1, how do I have to change the SAS code in order to get this result (master) dataset:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="stock_want.JPG" style="width: 361px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70239iD65FEF882BF565CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="stock_want.JPG" alt="stock_want.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;One the one hand, I want to update existing rows in the master dataset (partno="K89R") but also on the other hand, i want to add rows, that only exist in the transaction dataset (partno="M123").&lt;/P&gt;
&lt;P&gt;This is the code, I have so far, making use of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1exbj4v17dndpn1402cwa93cnfx.htm#p0uu7tgb9qg31tn1q4p91ik53u8a" target="_self"&gt;SYSRC Autocall Macro&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data stock;
	modify stock trans;
	by partno;

	select(_IORC_);
		when (%sysrc(_SOK))
			do;
				replace stock;
			end;

		when (%sysrc(_DSENMR))
			do;
				/*what kind of code must be here in order to add nonexisting observations in masterdataaset?*/
			end;

		otherwise
			do;
				put 'ERROR: Unexpected value for _IORC_= ' _iorc_;
				put 'Program terminating. Data step iteration # ' _n_;
				put _all_;
				stop;
			end;
	 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also my qustion is: how would I have to modify the code if I wanted to update not just one column but several columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated,&lt;/P&gt;
&lt;P&gt;FK1&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2022 12:57:49 GMT</pubDate>
    <dc:creator>FK1</dc:creator>
    <dc:date>2022-04-08T12:57:49Z</dc:date>
    <item>
      <title>Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806755#M317920</link>
      <description>&lt;P&gt;&amp;nbsp;Hello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This Knowledge Base entry shows examples for using the "modify" statement:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/24/678.html" target="_self"&gt;https://support.sas.com/kb/24/678.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding example 1, how do I have to change the SAS code in order to get this result (master) dataset:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="stock_want.JPG" style="width: 361px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70239iD65FEF882BF565CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="stock_want.JPG" alt="stock_want.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;One the one hand, I want to update existing rows in the master dataset (partno="K89R") but also on the other hand, i want to add rows, that only exist in the transaction dataset (partno="M123").&lt;/P&gt;
&lt;P&gt;This is the code, I have so far, making use of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1exbj4v17dndpn1402cwa93cnfx.htm#p0uu7tgb9qg31tn1q4p91ik53u8a" target="_self"&gt;SYSRC Autocall Macro&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data stock;
	modify stock trans;
	by partno;

	select(_IORC_);
		when (%sysrc(_SOK))
			do;
				replace stock;
			end;

		when (%sysrc(_DSENMR))
			do;
				/*what kind of code must be here in order to add nonexisting observations in masterdataaset?*/
			end;

		otherwise
			do;
				put 'ERROR: Unexpected value for _IORC_= ' _iorc_;
				put 'Program terminating. Data step iteration # ' _n_;
				put _all_;
				stop;
			end;
	 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also my qustion is: how would I have to modify the code if I wanted to update not just one column but several columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated,&lt;/P&gt;
&lt;P&gt;FK1&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 12:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806755#M317920</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2022-04-08T12:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806759#M317923</link>
      <description>&lt;P&gt;In order for anyone to write code to convert two input data sets into one output data set, we need to have the two input data sets. Please provide these two input data sets (or a small portion of each) as SAS data step code, which you can type in yourself, or you can use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; to create the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MODIFY statement doesn't apply to DATA steps.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806759#M317923</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-08T13:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806760#M317924</link>
      <description>&lt;P&gt;You are using the REPLACE statement to update an existing observation.&lt;/P&gt;
&lt;P&gt;Use the OUTPUT statement to write a new observation.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806760#M317924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-08T13:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806762#M317925</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;: the creation of the two datasets is also in the knowled base entry, which i posted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create STOCK data set */

data stock;
  input partno $ desc $ instock price;
datalines;
K89R seal 34 245.00
M4J7 sander 98 45.88
LK43 filter 121 10.99
MN21 brace 43 27.87
;

data trans;
  input partno $ desc $ instock price;
datalines;
K89R seal 34 300
M123 sander 98 45.88
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806762#M317925</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2022-04-08T13:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806766#M317928</link>
      <description>&lt;P&gt;This would be done using the DATA step UPDATE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=stock; by partno; run;
proc sort data=trans; by partno; run;
data want;
    update stock trans;
    by partno;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806766#M317928</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-08T13:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806774#M317933</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;: this works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data stock;
	modify stock trans;
	by partno;

	select(_IORC_);
		when (%sysrc(_SOK))
			do;
				replace stock;
			end;

		when (%sysrc(_DSENMR))
			do;
				output;
				_error_=0;
			end;

		otherwise
			do;
				put 'ERROR: Unexpected value for _IORC_= ' _iorc_;
				put 'Program terminating. Data step iteration # ' _n_;
				put _all_;
				stop;
			end;
	 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806774#M317933</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2022-04-08T13:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step with Modifiy Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806775#M317934</link>
      <description>&lt;P&gt;There is a difference between the UPDATE statement and what can be done with the MODIFY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main differences are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step using an UPDATE statement will write a whole NEW output dataset.&amp;nbsp; With MODIFY you can modify can existing dataset.&amp;nbsp; So if the source dataset is large and there might be a large difference in performance and disk space requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UPDATE statement will ignore missing values in the transaction dataset, leaving the existing value unchanged&amp;nbsp; If you use MODIFY to perform transactions you would need to add your own logic if you want that.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-with-Modifiy-Statement/m-p/806775#M317934</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-08T13:55:25Z</dc:date>
    </item>
  </channel>
</rss>

