<?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: update statement using if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945267#M370360</link>
    <description>&lt;P&gt;See &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_055/sqlproc/p0z9p6hclwnhxin1mrewxhdz5f26.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  set SASHELP.CLASS;
  if NAME='Alice' then AGE=.;
run;

proc sql;
  update HAVE a
  set AGE = (select AGE from SASHELP.CLASS b where a.NAME=b.NAME)
  where a.AGE = .;  inner join
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit:&lt;/P&gt;
&lt;P&gt;Adding that the &lt;CODE class=" language-sas"&gt;inner join&lt;/CODE&gt; syntax would be a lot more efficient for large updates, but does not seem to be supported by SAS.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 18:16:43 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2024-09-26T18:16:43Z</dc:date>
    <item>
      <title>update statement using if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945253#M370346</link>
      <description>&lt;P&gt;I am trying to update one column in one table using value from another table as below.&lt;/P&gt;&lt;P&gt;Is there a way to update the column only if it has null value or else keep the previous value and do no updates. Please let me know what wrong I am doing in the code below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	update table customer a
		set a.pre_diags =&amp;nbsp; 
			case
				when&amp;nbsp; a.pre_diags is null then b.pre_diags 
				else a.pre_diags
			end 
		from retails b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 18:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945253#M370346</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-25T18:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: update statement using if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945267#M370360</link>
      <description>&lt;P&gt;See &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_055/sqlproc/p0z9p6hclwnhxin1mrewxhdz5f26.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  set SASHELP.CLASS;
  if NAME='Alice' then AGE=.;
run;

proc sql;
  update HAVE a
  set AGE = (select AGE from SASHELP.CLASS b where a.NAME=b.NAME)
  where a.AGE = .;  inner join
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit:&lt;/P&gt;
&lt;P&gt;Adding that the &lt;CODE class=" language-sas"&gt;inner join&lt;/CODE&gt; syntax would be a lot more efficient for large updates, but does not seem to be supported by SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 18:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945267#M370360</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-09-26T18:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: update statement using if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945269#M370362</link>
      <description>&lt;P&gt;You are testing in the wrong place. Apply the test when selecting which observations to update.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;update CUSTOMER a
  set PRE_DIAGS = (......)
  where missing(PRE_DIAGS)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also which of the values of PRE_DIAGS in RETAILS do you want to use to replace the current observations value of PRE_DIAGS in CUSTOMER??&lt;/P&gt;
&lt;P&gt;Is there some type of customer id in both datasets that could be used to know where in RETAILS to look?&amp;nbsp; Could the same customer appear more than once in RETAILS? If so which value do you want to use?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;update CUSTOMER a
  set PRE_DIAGS = 
    (select max(b.pre_diags) from RETAILS b 
      where a.customer_id  = b.customer_id)
  where missing(PRE_DIAGS)
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2024 20:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-statement-using-if-statement/m-p/945269#M370362</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-25T20:14:49Z</dc:date>
    </item>
  </channel>
</rss>

