<?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: how to update multiple row using single row  value from another file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893476#M352978</link>
    <description>Tom,&lt;BR /&gt;You are right. My code is based on the data OP posted.&lt;BR /&gt;It is all depended on what OP look for.&lt;BR /&gt;&lt;BR /&gt;For your special case, you could&lt;BR /&gt; PROC SORT data=master; by id score;run;&lt;BR /&gt;firstly before UPDATE .&lt;BR /&gt;Of course .it is all depended on what OP want .</description>
    <pubDate>Sun, 10 Sep 2023 09:08:16 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-09-10T09:08:16Z</dc:date>
    <item>
      <title>how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893386#M352920</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;I have two dataset (master and update) like below and I would like to update `master`&amp;nbsp; using update.score if master.score=. .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stataq_0-1694206715767.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87737iC11823BF30D3C011/image-size/large?v=v2&amp;amp;px=999" role="button" title="stataq_0-1694206715767.png" alt="stataq_0-1694206715767.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How can I achieve expected outputs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do it like below and got "ERROR: Subquery evaluated to more than one row."&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;P&gt;data output;&lt;BR /&gt;update master update;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 01:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893386#M352920</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2023-09-10T01:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893392#M352923</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick search for the error message&amp;nbsp;&lt;SPAN&gt;ERROR: Subquery evaluated to more than one row. brings back links for proc SQL, as opposed to data step code like you shared.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please post the log showing the &lt;EM&gt;code&lt;/EM&gt; and any &lt;EM&gt;messages&lt;/EM&gt; using the Insert Code icon "&amp;lt;/&amp;gt;" when posting.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, is there any difference if you use a different data set name for your transaction data set, as &lt;FONT face="courier new,courier"&gt;update&lt;/FONT&gt; is a keyword and can cause its own error, e.g.:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 80         data update;
                 ______
                 56
 ERROR 56-185: UPDATE is not allowed in the DATA statement when option DATASTMTCHK=COREKEYWORDS.  Check for a missing semicolon in 
               the DATA statement, or use DATASTMTCHK=NONE.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks &amp;amp; kind regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 22:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893392#M352923</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-08T22:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893411#M352931</link>
      <description>&lt;P&gt;The error message you share is from a SQL but the code you share is a data step. You will often get better answers faster if you spend a bit more time formulating the question. You will also get answers faster if you share sample data via working SAS data steps as done below and not just via screenshots.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.master;
  infile datalines truncover dsd;
  input id score work $1.;
  datalines;
1,,Y
1,7,N
2,5,Y
3,,N
;

data work.update;
  infile datalines truncover dsd;
  input id score;
  datalines;
1,8
2,6
3,5
4,6
;

proc sql;
  update work.master as m
    set score=(select score from work.update where id=m.id)
    where missing(m.score)
    ;
  select * from work.master;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;...and if you use two level table names then you will also never hit issues like below where you get an error because a table name is also a SAS keyword (update in this case).&lt;/P&gt;
&lt;PRE&gt; ERROR 56-185: UPDATE is not allowed in the DATA statement when option DATASTMTCHK=COREKEYWORDS.  Check for a missing semicolon in 
               the DATA statement, or use DATASTMTCHK=NONE.&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2023 05:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893411#M352931</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-09T05:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893412#M352932</link>
      <description>&lt;P&gt;A slightly different approach;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table new as
   select a.id, a.work, coalesce(a.score,b.score) as score
   from work.master as a
        left join
        work.update as b
        on a.id=b.id
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;I tend to be very cautious about update in place until I am very sure of both data sets and the result so the above creates a new dataset.&lt;/P&gt;
&lt;P&gt;The Coalesce, or for character values Coalescec, function returns the first of the non-missing values from the list of values. So this replaces the missing values in the set aliased as A with those in B.&lt;/P&gt;
&lt;P&gt;Coalesce will take more than two parameters, so you could have multiple variables and/or a fixed value added to set the value if all of the variables are missing (no match in the update set for example).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both this and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s solution will require that there only be one value of ID in the UPDATE set.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 05:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893412#M352932</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-09T05:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893431#M352946</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.master;
  infile datalines truncover dsd;
  input id score work $1.;
  datalines;
1,,Y
1,7,N
2,5,Y
3,,N
;

data work.update;
  infile datalines truncover dsd;
  input id score;
  datalines;
1,8
2,6
3,5
4,6
;

data want;
 update update master(in=inb);
 by id;
 if inb then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2023 10:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893431#M352946</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-09T10:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893452#M352957</link>
      <description>&lt;P&gt;So this is reversing the order of the original and transactions datasets in the UPDATE statement can have useful applications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp;in this case it is probably not correct.&amp;nbsp; The problem will be when the original dataset has some values populated and some values missing then what the missing is replaced with is probably not what the original poster intended.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider the case where your ORIGINAL dataset looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.original;
  input id score ;
datalines;
1 . 
1 7 
1 . 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And your transaction dataset has :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.transactions;
  input id score;
datalines;
1 8
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you apply your method of treating the transactions as the original and the original as the transcations:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want ;
  update work.transactions work.original(in=in_original);
  by id;
  if in_original then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second missing value of SCORE is replaced with the preceding value,7, instead of the value from transactions datasets which is 8.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 19:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893452#M352957</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-09T19:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to update multiple row using single row  value from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893476#M352978</link>
      <description>Tom,&lt;BR /&gt;You are right. My code is based on the data OP posted.&lt;BR /&gt;It is all depended on what OP look for.&lt;BR /&gt;&lt;BR /&gt;For your special case, you could&lt;BR /&gt; PROC SORT data=master; by id score;run;&lt;BR /&gt;firstly before UPDATE .&lt;BR /&gt;Of course .it is all depended on what OP want .</description>
      <pubDate>Sun, 10 Sep 2023 09:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-multiple-row-using-single-row-value-from-another/m-p/893476#M352978</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-10T09:08:16Z</dc:date>
    </item>
  </channel>
</rss>

