<?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: Updating value in multiple columns in Proc SQL? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331203#M62693</link>
    <description>&lt;P&gt;Thanks for your advice. &amp;nbsp;I'm trying to learn how to change the value in PROC SQL. &amp;nbsp;I have done this in data step.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2017 15:53:55 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2017-02-09T15:53:55Z</dc:date>
    <item>
      <title>Updating value in multiple columns in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331179#M62689</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to update the multiple values in different columns. &amp;nbsp;I wrote a code below, &amp;nbsp;The log shows in the Syntax error. &amp;nbsp;Please help. &amp;nbsp;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;338 PROC SQL;&lt;BR /&gt;339 update work.test&lt;BR /&gt;340 set age=age&lt;BR /&gt;341 case&lt;BR /&gt;----&lt;BR /&gt;22&lt;BR /&gt;202&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !!, (, *, **, +, ',', -, '.', /,&lt;BR /&gt;WHERE, ||.&lt;/P&gt;&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;342 when age in (1,2,3,4,5) then age=1&lt;BR /&gt;----&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, &amp;amp;, AND, OR, |.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;343 when age in (6,7,8,9) then age=2&lt;BR /&gt;344 when age in (10,11,12,13) then age=3&lt;BR /&gt;345 end;&lt;BR /&gt;346 , set marital=marital&lt;BR /&gt;-&lt;BR /&gt;180&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;347 case&lt;BR /&gt;348 when marital in (2, 4) then marital=2&lt;BR /&gt;349 end;&lt;BR /&gt;350 , set education=education&lt;BR /&gt;-&lt;BR /&gt;180&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;351 case&lt;BR /&gt;352 when education in (1,2) then education=1&lt;BR /&gt;353 when education in (3,4) then education=2&lt;BR /&gt;354 when education in (5.6) then education=3&lt;BR /&gt;355 end;&lt;BR /&gt;356 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 15:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331179#M62689</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T15:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Updating value in multiple columns in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331180#M62690</link>
      <description>&lt;P&gt;My original codes is list below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;update work.test&lt;BR /&gt;set age=age&lt;BR /&gt;case&lt;BR /&gt;when age in (1,2,3,4,5) then age=1&lt;BR /&gt;when age in (6,7,8,9) then age=2&lt;BR /&gt;when age in (10,11,12,13) then age=3&lt;BR /&gt;end;&lt;BR /&gt;, set marital=marital&lt;BR /&gt;case&lt;BR /&gt;when marital in (2, 4) then marital=2&lt;BR /&gt;end;&lt;BR /&gt;, set education=education&lt;BR /&gt;case&lt;BR /&gt;when education in (1,2) then education=1&lt;BR /&gt;when education in (3,4) then education=2&lt;BR /&gt;when education in (5.6) then education=3&lt;BR /&gt;end;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 15:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331180#M62690</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T15:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Updating value in multiple columns in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331197#M62692</link>
      <description>&lt;P&gt;Am afraid there is several problems with that code, semicolons all over the place, case statements invalid, assignments wrong, no from, and update doesn't work like that anyways. &amp;nbsp;Too much to waste time fixing. &amp;nbsp;Why not just do a very simple datastep:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  select(age);
    when (1,2,3,4,5) age=1;
    when (6,7,8,9) age=2;
    otherwise age=3;
  end;
...
run;&lt;/PRE&gt;
&lt;P&gt;Alternatively post some test data in the form of a datastep so that we have something to work with&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 15:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331197#M62692</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-09T15:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Updating value in multiple columns in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331203#M62693</link>
      <description>&lt;P&gt;Thanks for your advice. &amp;nbsp;I'm trying to learn how to change the value in PROC SQL. &amp;nbsp;I have done this in data step.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 15:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331203#M62693</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T15:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Updating value in multiple columns in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331216#M62698</link>
      <description>&lt;P&gt;Well, its probably a good idea to start from the basics then. &amp;nbsp;Your code has lots of problems. &amp;nbsp;This code demonstrates how to to an update - note it will affect &lt;STRONG&gt;all&amp;nbsp;&lt;/STRONG&gt;rows as there is no where.&lt;/P&gt;
&lt;PRE&gt;data test;
  set sashelp.class;
run;

proc sql;
  update TEST 
  set AGE=case when AGE in (14,13) then 1
               when AGE in (11,12) then 2
               else 3 end,
      HEIGHT=case when HEIGHT &amp;lt; 63 then 1
                  else 2 end;
quit;
      &lt;/PRE&gt;
&lt;P&gt;You will see semicolon is only at the end of the SQL. &amp;nbsp;Variables are delimited by commas, set appears only once, case statement is different. &amp;nbsp;These are basic SQL things which you should be learning before trying to do more advanced tasks like updating and joining. &amp;nbsp;(and presenting code in a the code window - {i} and using consistent casing/indetation and such like makes reading code easier).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 16:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Updating-value-in-multiple-columns-in-Proc-SQL/m-p/331216#M62698</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-09T16:14:47Z</dc:date>
    </item>
  </channel>
</rss>

