<?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: I want to update the value of one column in sas data set based on value of another column in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914099#M44245</link>
    <description>&lt;P&gt;Short version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cer_users;
set cer_users;
if ord_creatr_user_id ='987' and Initiative = 'UnderGrad'
then Initiative ='UC-UnderGrad';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you can also run your SQL code in PROC SQL;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2024 20:12:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-02-01T20:12:06Z</dc:date>
    <item>
      <title>I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914091#M44244</link>
      <description>&lt;P&gt;Hello Experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with about 10 columns, I want to update the column value of one column based on value of another column , how can I do that&lt;/P&gt;&lt;P&gt;something like this on sql but I need to update SAS dataset&amp;nbsp;Cer_Users where&amp;nbsp;Initiative &amp;amp; ord_creatr_user_id&amp;nbsp; are columns&amp;nbsp;&lt;/P&gt;&lt;P&gt;UPDATE Cer_Users&lt;BR /&gt;SET Initiative = CASE WHEN ord_creatr_user_id ='987' and Initiative = 'UnderGrad'&lt;BR /&gt;THEN 'UC-UnderGrad'&lt;BR /&gt;ELSE Initiative&lt;BR /&gt;END&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 20:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914091#M44244</guid>
      <dc:creator>Froebel</dc:creator>
      <dc:date>2024-02-01T20:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914099#M44245</link>
      <description>&lt;P&gt;Short version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cer_users;
set cer_users;
if ord_creatr_user_id ='987' and Initiative = 'UnderGrad'
then Initiative ='UC-UnderGrad';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you can also run your SQL code in PROC SQL;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 20:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914099#M44245</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-01T20:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914102#M44246</link>
      <description>Thank you. I tried proc sql but the&lt;BR /&gt;update command under proc sql is not recognized.( The update text does not turn blue like the select text )</description>
      <pubDate>Thu, 01 Feb 2024 20:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914102#M44246</guid>
      <dc:creator>Froebel</dc:creator>
      <dc:date>2024-02-01T20:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914103#M44247</link>
      <description>&lt;P&gt;The coloring in the SAS editor is not 100% perfect.&lt;/P&gt;
&lt;P&gt;See the documentation of the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p0ci36zwxhm1xdn1a943yeczfalk.htm" target="_blank" rel="noopener"&gt;UPDATE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 20:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914103#M44247</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-01T20:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914138#M44248</link>
      <description>&lt;P&gt;Looks ok to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you are unsure try it first on a COPY of the dataset.&amp;nbsp; In fact I would avoid using the SQL UPDATE statement unless there is no other way to get what you want because of the risks involved in modifying an existing dataset. If it doesn't work as expected you will need to have a back up the original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your UPDATE statement can be simpler (and faster and safer) if you eliminate the CASE and use an actual WHERE clause instead.&amp;nbsp; That way you are only changing the observations that need changing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;UPDATE Cer_Users
  SET Initiative = 'UC-UnderGrad'
  WHERE ord_creatr_user_id ='987' and Initiative = 'UnderGrad'
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note it is normally much easier, clearer and safer to just use normal SAS code than try to figure out how to do things with SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here is a data step to make a NEW dataset with the fixed values.&amp;nbsp; That way you can always go back to the original dataset if the logic or the coding was incorrect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fixed_cer_users;
  set cer_users;
  if ord_creatr_user_id ='987' and Initiative = 'UnderGrad' then 
      Initiative = 'UC-UnderGrad'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 23:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914138#M44248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-01T23:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: I want to update the value of one column in sas data set based on value of another column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914139#M44249</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431894"&gt;@Froebel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Experts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set with about 10 columns, I want to update the column value of one column based on value of another column , how can I do that&lt;/P&gt;
&lt;P&gt;something like this on sql but I need to update SAS dataset&amp;nbsp;Cer_Users where&amp;nbsp;Initiative &amp;amp; ord_creatr_user_id&amp;nbsp; are columns&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE Cer_Users&lt;BR /&gt;SET Initiative = CASE WHEN ord_creatr_user_id ='987' and Initiative = 'UnderGrad'&lt;BR /&gt;THEN 'UC-UnderGrad'&lt;BR /&gt;ELSE Initiative&lt;BR /&gt;END&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your SQL would update all rows but in the else case with the original value (=no change).&lt;/P&gt;
&lt;P&gt;It would be more efficient it you only update the rows where the value actually needs to change using code as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  UPDATE Cer_Users
  SET Initiative = 'UC-UnderGrad'
  WHERE ord_creatr_user_id ='987' and Initiative = 'UnderGrad'
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2024 23:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/I-want-to-update-the-value-of-one-column-in-sas-data-set-based/m-p/914139#M44249</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-01T23:52:54Z</dc:date>
    </item>
  </channel>
</rss>

