<?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 Proc SQL issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63196#M13739</link>
    <description>I'm posting this code that works in Microsoft SQL server, but not in Proc SQL.  I can't figure out why.  I am also posting how I changed it using Proc SQL and then the error I get.  Can anyone help?&lt;BR /&gt;
&lt;BR /&gt;
update t_captreatment&lt;BR /&gt;
set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
from&lt;BR /&gt;
t_captreatment a,&lt;BR /&gt;
t_rep b&lt;BR /&gt;
where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid)&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
update t_captreatment&lt;BR /&gt;
set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
from&lt;BR /&gt;
t_captreatment a,&lt;BR /&gt;
t_rep b&lt;BR /&gt;
where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid);&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
1          ;*';*";*/;quit;run;&lt;BR /&gt;
2          OPTIONS PAGENO=MIN;&lt;BR /&gt;
3          %LET _CLIENTTASKLABEL=%NRBQUOTE(Code);&lt;BR /&gt;
4          %LET _EGTASKLABEL=%NRBQUOTE(Code);&lt;BR /&gt;
5          %LET _CLIENTPROJECTNAME=%NRBQUOTE();&lt;BR /&gt;
6          %LET _SASPROGRAMFILE=;&lt;BR /&gt;
7          &lt;BR /&gt;
8          ODS _ALL_ CLOSE;&lt;BR /&gt;
NOTE: Some of your options or statements may not be supported with the Activex or Java series of devices.  Graph defaults for these &lt;BR /&gt;
      drivers may be different from other SAS/GRAPH device drivers.  For further information, please contact Technical Support.&lt;BR /&gt;
9          OPTIONS DEV=ACTIVEX;&lt;BR /&gt;
10         &lt;BR /&gt;
11         %gaccessible;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
12         PROC SQL;&lt;BR /&gt;
13         update t_captreatment&lt;BR /&gt;
14         set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
15         id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
16         id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
17         id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
18         from&lt;BR /&gt;
           ____&lt;BR /&gt;
           22&lt;BR /&gt;
           76&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, WHERE, ||.  &lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
19         t_captreatment a,&lt;BR /&gt;
20         t_rep b&lt;BR /&gt;
21         where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
22         or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
23         or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
24         or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid);&lt;BR /&gt;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;
25         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.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
      &lt;BR /&gt;
26         &lt;BR /&gt;
27         &lt;BR /&gt;
28         &lt;BR /&gt;
29         %LET _CLIENTTASKLABEL=;&lt;BR /&gt;
30         %LET _EGTASKLABEL=;&lt;BR /&gt;
31         %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;
32         %LET _SASPROGRAMFILE=;&lt;BR /&gt;
33         &lt;BR /&gt;
34         ;*';*";*/;quit;run;&lt;BR /&gt;
35         ODS _ALL_ CLOSE;&lt;BR /&gt;
36         &lt;BR /&gt;
37         &lt;BR /&gt;
38         QUIT; RUN;&lt;BR /&gt;
39</description>
    <pubDate>Wed, 26 Nov 2008 15:03:51 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-11-26T15:03:51Z</dc:date>
    <item>
      <title>Proc SQL issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63196#M13739</link>
      <description>I'm posting this code that works in Microsoft SQL server, but not in Proc SQL.  I can't figure out why.  I am also posting how I changed it using Proc SQL and then the error I get.  Can anyone help?&lt;BR /&gt;
&lt;BR /&gt;
update t_captreatment&lt;BR /&gt;
set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
from&lt;BR /&gt;
t_captreatment a,&lt;BR /&gt;
t_rep b&lt;BR /&gt;
where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid)&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
update t_captreatment&lt;BR /&gt;
set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
from&lt;BR /&gt;
t_captreatment a,&lt;BR /&gt;
t_rep b&lt;BR /&gt;
where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid);&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
1          ;*';*";*/;quit;run;&lt;BR /&gt;
2          OPTIONS PAGENO=MIN;&lt;BR /&gt;
3          %LET _CLIENTTASKLABEL=%NRBQUOTE(Code);&lt;BR /&gt;
4          %LET _EGTASKLABEL=%NRBQUOTE(Code);&lt;BR /&gt;
5          %LET _CLIENTPROJECTNAME=%NRBQUOTE();&lt;BR /&gt;
6          %LET _SASPROGRAMFILE=;&lt;BR /&gt;
7          &lt;BR /&gt;
8          ODS _ALL_ CLOSE;&lt;BR /&gt;
NOTE: Some of your options or statements may not be supported with the Activex or Java series of devices.  Graph defaults for these &lt;BR /&gt;
      drivers may be different from other SAS/GRAPH device drivers.  For further information, please contact Technical Support.&lt;BR /&gt;
9          OPTIONS DEV=ACTIVEX;&lt;BR /&gt;
10         &lt;BR /&gt;
11         %gaccessible;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
12         PROC SQL;&lt;BR /&gt;
13         update t_captreatment&lt;BR /&gt;
14         set id_num4 = (case when (a.id_type4 = 'REP_ID' and id_untrans4 = b.adprepid) then b.rep_id else id_num4 end),&lt;BR /&gt;
15         id_num3 = (case when (a.id_type3 = 'REP_ID' and id_untrans3 = b.adprepid) then b.rep_id else id_num3 end),&lt;BR /&gt;
16         id_num2 = (case when (a.id_type2 = 'REP_ID' and id_untrans2 = b.adprepid) then b.rep_id else id_num2 end),&lt;BR /&gt;
17         id_num1 = (case when (a.id_type1 = 'REP_ID' and id_untrans1 = b.adprepid) then b.rep_id else id_num1 end)&lt;BR /&gt;
18         from&lt;BR /&gt;
           ____&lt;BR /&gt;
           22&lt;BR /&gt;
           76&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, WHERE, ||.  &lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
19         t_captreatment a,&lt;BR /&gt;
20         t_rep b&lt;BR /&gt;
21         where (a.id_type4 = 'REP_ID' and a.id_untrans4 = b.adprepid)&lt;BR /&gt;
22         or (a.id_type3 = 'REP_ID' and a.id_untrans3 = b.adprepid)&lt;BR /&gt;
23         or (a.id_type2 = 'REP_ID' and a.id_untrans2 = b.adprepid)&lt;BR /&gt;
24         or (a.id_type1 = 'REP_ID' and a.id_untrans1 = b.adprepid);&lt;BR /&gt;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;
25         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.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
      &lt;BR /&gt;
26         &lt;BR /&gt;
27         &lt;BR /&gt;
28         &lt;BR /&gt;
29         %LET _CLIENTTASKLABEL=;&lt;BR /&gt;
30         %LET _EGTASKLABEL=;&lt;BR /&gt;
31         %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;
32         %LET _SASPROGRAMFILE=;&lt;BR /&gt;
33         &lt;BR /&gt;
34         ;*';*";*/;quit;run;&lt;BR /&gt;
35         ODS _ALL_ CLOSE;&lt;BR /&gt;
36         &lt;BR /&gt;
37         &lt;BR /&gt;
38         QUIT; RUN;&lt;BR /&gt;
39</description>
      <pubDate>Wed, 26 Nov 2008 15:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63196#M13739</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-26T15:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63197#M13740</link>
      <description>Check the documentation.  SAS's implementation of the UPDATE statement does not support the FROM clause.</description>
      <pubDate>Wed, 26 Nov 2008 17:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63197#M13740</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2008-11-26T17:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63198#M13741</link>
      <description>Thanks for your response, but I'm struggling with how it should be written then.  I've tried so many things, but it still doesn't work.  Without using the From clause, how would the program know what table to reference?</description>
      <pubDate>Wed, 26 Nov 2008 18:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63198#M13741</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-26T18:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63199#M13742</link>
      <description>Well, you can use in-line views in your set statement together with a where-clause. See my example on SASHELP.CLASS:&lt;BR /&gt;
&lt;BR /&gt;
data classGrade;&lt;BR /&gt;
	input name $ grade $;&lt;BR /&gt;
	datalines;&lt;BR /&gt;
Alfred A&lt;BR /&gt;
Barbara C&lt;BR /&gt;
Janet D&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data class;&lt;BR /&gt;
	set sashelp.class;&lt;BR /&gt;
	length eval $6;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
update class as a&lt;BR /&gt;
set eval = (select case when grade = 'A' then 'GOOD' when 'D' then 'BAD' else 'MEDIUM' end&lt;BR /&gt;
				from classGrade as b &lt;BR /&gt;
				where a.name eq b.name)&lt;BR /&gt;
where a.name in(select name from classGrade)&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
If your data is large, I think performance could be an issue with this SQL. To prevent long running updates, index your transaction table on the id column(s).&lt;BR /&gt;
&lt;BR /&gt;
Another option is simply to recreate the table using a join to do your calculation.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Wed, 26 Nov 2008 21:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-issue/m-p/63199#M13742</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-11-26T21:47:35Z</dc:date>
    </item>
  </channel>
</rss>

