<?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 Update statement in PROC sql? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331272#M62707</link>
    <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got this error message from the log, &amp;nbsp; Please advice how to fix it, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;640 PROC SQL;&lt;BR /&gt;641 update work.test&lt;BR /&gt;642 set age=case when age in (1,2,3,4,5) then 1&lt;BR /&gt;643 when age in (6,7,8,9) then 2&lt;BR /&gt;644 when age in (10,11,12,13) then 3 end,&lt;BR /&gt;645 set EDUCATION=case when EDUCATION in (1,2) then 1&lt;BR /&gt;---------&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;646 when EDUCATION in (3,4) then 2&lt;BR /&gt;647 when EDUCATION in (5.6) then 3 end;&lt;BR /&gt;648 quit;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2017 18:24:49 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2017-02-09T18:24:49Z</dc:date>
    <item>
      <title>Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331272#M62707</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got this error message from the log, &amp;nbsp; Please advice how to fix it, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;640 PROC SQL;&lt;BR /&gt;641 update work.test&lt;BR /&gt;642 set age=case when age in (1,2,3,4,5) then 1&lt;BR /&gt;643 when age in (6,7,8,9) then 2&lt;BR /&gt;644 when age in (10,11,12,13) then 3 end,&lt;BR /&gt;645 set EDUCATION=case when EDUCATION in (1,2) then 1&lt;BR /&gt;---------&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;646 when EDUCATION in (3,4) then 2&lt;BR /&gt;647 when EDUCATION in (5.6) then 3 end;&lt;BR /&gt;648 quit;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 18:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331272#M62707</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T18:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331275#M62708</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
update work.test
set 

age=case when age in (1,2,3,4,5) then 1
when age in (6,7,8,9) then 2
when age in (10,11,12,13) then 3 end,

EDUCATION=case when EDUCATION in (1,2) then 1
when EDUCATION in (3,4) then 2
when EDUCATION in (5.6) then 3 end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2017 18:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331275#M62708</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-09T18:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331276#M62709</link>
      <description>This also appears to be directly related to another post you made a few hours ago.  You should keep you follow up questions attached to the original thread...</description>
      <pubDate>Thu, 09 Feb 2017 18:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331276#M62709</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-09T18:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331281#M62710</link>
      <description>&lt;P&gt;I got a note as shown below. &amp;nbsp;Does this mean I have to else in the "case...when"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result&lt;BR /&gt;in a missing value for the CASE expression.&lt;BR /&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result&lt;BR /&gt;in a missing value for the CASE expression.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 18:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331281#M62710</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T18:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331283#M62712</link>
      <description>Yes, that is what it means, which is fine, if that's the functionality you want.  I will assume it not.  So you would want to add and:&lt;BR /&gt;&lt;BR /&gt;else AGE/EDUCATION before the end on your two case statements</description>
      <pubDate>Thu, 09 Feb 2017 18:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331283#M62712</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2017-02-09T18:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331314#M62714</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;This does not answer you question, however my limited knowledge makes me believe.

1. Relational: SQL tables generally have a unique key that enable updates
2, set must resolve to one value per key
3. You need a relational object for your case statement to operate on


SAS: Using proc sql to update missing values

Change missing ages to 99 using a transaction dataset

HAVE    MASTER and TRANSACTION datsets
====

Up to 40 obs WORK.MASTER total obs=19

Obs    NAME        SEX  AGE

  1    Alfred       M     .
  2    Alice        F     .
  3    Barbara      F     .
  4    Carol        F     .
  5    Henry        M     .
  6    James        M    12
  7    Jane         F    12
  8    Janet        F    15
  9    Jeffrey      M     .
 10    John         M    12
 11    Joyce        F    11
 12    Judy         F     .
 13    Louise       F    12
 14    Mary         F    15
 15    Philip       M    16
 16    Robert       M    12
 17    Ronald       M    15
 18    Thomas       M    11
 19    William      M    15


Up to 40 obs WORK.TRANSACTION total obs=10

Obs    NAME        SEX AGE

  1    Alfred       M   14
  2    Alice        F   13
  3    Barbara      F   13
  4    Carol        F   14
  5    Henry        M   14
  6    James        M   12
  7    Jane         F   12
  8    Janet        F   15
  9    Jeffrey      M   13
 10    John         M   12


WANT  New master
================

Up to 40 obs from master total obs=19

Obs    NAME        SEX             AGE

  1    Alfred       M               99
  2    Alice        F               99
  3    Barbara      F               99
  4    Carol        F               99
  5    Henry        M               99

  6    James        M               12
  7    Jane         F               12
  8    Janet        F               15

  9    Jeffrey      M               99

 10    John         M               12
 11    Joyce        F               11

 12    Judy         F                .  Not updated because only first 10
                                        are in the transaction dataset
 13    Louise       F               12
 14    Mary         F               15
 15    Philip       M               16
 16    Robert       M               12
 17    Ronald       M               15
 18    Thomas       M               11
 19    William      M               15


SOLUTION
========

SAS
===

data master;
  set sashelp.class(keep=name sex age);
  if age in (13,14) then age=.;
run;quit;

data transaction;
   set sashelp.class(obs=10 keep=name sex age);
run;quit;

proc sql;
select * from master;
update master as a
    set age=(
         select
             case
               when b.age in (13,14) then 99
               else a.age
             end as age
         from
             transaction as b
         where
             a.name=b.name)
where exists (select * from transaction as b where a.name=b.name );
select * from master;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2017 20:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331314#M62714</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-09T20:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331315#M62715</link>
      <description>Looks like I was wrong</description>
      <pubDate>Thu, 09 Feb 2017 20:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331315#M62715</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-09T20:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement in PROC sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331317#M62716</link>
      <description>&lt;P&gt;That is why I didn't use "else" in the AGE statement. &amp;nbsp;I was afraid that it will assign the "." into the 3 too.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 20:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Update-statement-in-PROC-sql/m-p/331317#M62716</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T20:43:05Z</dc:date>
    </item>
  </channel>
</rss>

