<?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: Replace values in a Dataset with a second dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824190#M35133</link>
    <description>&lt;P&gt;Take a look at the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p103b0p9akdcmhn1xbik9hbuo760.htm" target="_self"&gt;REPLACE statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jul 2022 16:17:45 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2022-07-19T16:17:45Z</dc:date>
    <item>
      <title>Replace values in a Dataset with a second dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824187#M35131</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have large dataset (named "one"). I noticed that some of the observations (but not all) for a particular variable (named "variable") are incorrect. I created a second dataset (named "two") with the same variable and the correct observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I replace the observations for the specific variable in dataset one with those from dataset two while stilling keepign everything else the same in the original dataset (named "one")?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To explain in more detail, I have created the scenario below. Essentially, how do I replace the variable values for Carol and David (4 and 5 respectively) in dataset one with those in dataset two (3 and 4 respectively) without affecting Anne, Bill, and Erik or the inputs for Car?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;input name$ variable car$;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Anne&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Acura&lt;/P&gt;&lt;P&gt;Bill&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; Buick&lt;/P&gt;&lt;P&gt;Carol&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; Cadillac&lt;/P&gt;&lt;P&gt;David&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; Dodge&lt;/P&gt;&lt;P&gt;Erik&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; Equus; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;input name variable;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Carol&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;David&amp;nbsp;&amp;nbsp; 4; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 16:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824187#M35131</guid>
      <dc:creator>tofov2</dc:creator>
      <dc:date>2022-07-19T16:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values in a Dataset with a second dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824189#M35132</link>
      <description>&lt;P&gt;The UPDATE statement does exactly this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input name$ variable car$;
datalines;
Anne    1     Acura
Bill        2    Buick
Carol    4    Cadillac
David   5    Dodge
Erik      5    Equus
; 
run;

 

data two;
input name $ variable;
datalines;
Carol    3
David   4
; 
run;

 data three;
 update one two;
 by name;
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2022 16:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824189#M35132</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-19T16:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values in a Dataset with a second dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824190#M35133</link>
      <description>&lt;P&gt;Take a look at the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p103b0p9akdcmhn1xbik9hbuo760.htm" target="_self"&gt;REPLACE statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 16:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824190#M35133</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-07-19T16:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values in a Dataset with a second dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824191#M35134</link>
      <description>&lt;P&gt;First, two issues with the example data. The datalines end with a semicolon on a row by itself. If you have the semicolon on a row with data that record will not be in the output data set. Second, you did not have Name as the same type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input name$ variable car$;
datalines;
Anne    1     Acura
Bill        2    Buick
Carol    4    Cadillac
David   5    Dodge
Erik      5    Equus
; run;
 
data two;
input name $ variable;
datalines;
Carol    3
David   4
; run;

/* if not sorted by variables that uniquely identify records do so*/

data want;
   update one two;
   by name;
run;&lt;/PRE&gt;
&lt;P&gt;The Update statement will replace values and add records from Two to the data set One. Match By variables that uniquely identify records in data set one. If the By variables duplicate in One this will fail.&lt;/P&gt;
&lt;P&gt;The default behavior for Update is that missing values in the second set will not replace values in the first. If you want that behavior you would add the option UPDATEMODE=NOMISSINGCHECK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: You can replace the first the data set but I would create a new data set until you are very familiar with the behavior the update statement.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 16:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-in-a-Dataset-with-a-second-dataset/m-p/824191#M35134</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-19T16:22:13Z</dc:date>
    </item>
  </channel>
</rss>

