<?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: Proc SQL how to use SET FROM statement correctly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952375#M372221</link>
    <description>&lt;P&gt;Put a SUBQUERY after the = that returns only one value.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.class;
run;
data other;
  set sashelp.class(obs=5);
  keep name sex ;
  rename sex=gender;
run;
proc sql;
alter table have add gender char(1);
update have a
  set gender=(
  select b.gender from other b
  where b.name = a.name
  )
  where name in (select name from other)
;
quit;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Dec 2024 03:08:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-12-03T03:08:44Z</dc:date>
    <item>
      <title>Proc SQL how to use SET FROM statement correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952371#M372219</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I inherited a program with an existing querry that works by continually applying changes to a temp table in proc sql&amp;nbsp; but generates warning messages.&amp;nbsp; Here is the simplest part of that process:&lt;/P&gt;
&lt;PRE&gt;proc sql;

...

create table tempds as
select a.*,b.wantedcol
from tempds as a, othertable as b
where a.fkey1=b.sfkey1 and a.key2=b.key2;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;an example of the warning:&lt;BR /&gt;WARNING: This CREATE TABLE statement recursively references the target table. A consequence of this is a possible data integrity &lt;BR /&gt;problem.&lt;/P&gt;
&lt;P&gt;I want to fix this and stay within proc sql even though I could handle this specific example in a data step since I have more sql querries to fix.&lt;/P&gt;
&lt;P&gt;This is my attempt to fix, but I am doing something wrong between the SET statement and the FROM statement. I'm sure there is some slight syntax change I need but I cant figure out what needs updating&lt;/P&gt;
&lt;PRE&gt;PROC SQL;

...
ALTER TABLE tempds
ADD wantedcol num(3);

UPDATE tempds
SET wantedcol=b.wantedcol
FROM tempds a join othertable b
WHERE a.fkey=b.sfkey and a.key2=b.key2;
quit;&lt;/PRE&gt;
&lt;P&gt;The error is the following&amp;nbsp; at the FROM keyword:&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, WHERE, ||.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is sas 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using these 2 links as reference, and maybe sas's sql syntax is a bit different for the FROM keyword:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/sqlproc/n1hz0uhw57yye2n16m5r103jjpjj.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/vdmmlcdc/8.1/sqlproc/n1hz0uhw57yye2n16m5r103jjpjj.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/answers/questions/1166695/add-column-to-table-and-populate-from-another-tabl" target="_blank"&gt;https://learn.microsoft.com/en-us/answers/questions/1166695/add-column-to-table-and-populate-from-another-tabl&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952371#M372219</guid>
      <dc:creator>weg</dc:creator>
      <dc:date>2024-12-03T02:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL how to use SET FROM statement correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952372#M372220</link>
      <description>&lt;P&gt;Because the created table name is the same as the input table,.&lt;/P&gt;
&lt;P&gt;You could use option UNDOPOLICY=NONE to suppress this kind of warning info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql  undopolicy=none ;
..............&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952372#M372220</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-03T02:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL how to use SET FROM statement correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952375#M372221</link>
      <description>&lt;P&gt;Put a SUBQUERY after the = that returns only one value.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.class;
run;
data other;
  set sashelp.class(obs=5);
  keep name sex ;
  rename sex=gender;
run;
proc sql;
alter table have add gender char(1);
update have a
  set gender=(
  select b.gender from other b
  where b.name = a.name
  )
  where name in (select name from other)
;
quit;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 03:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-how-to-use-SET-FROM-statement-correctly/m-p/952375#M372221</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-03T03:08:44Z</dc:date>
    </item>
  </channel>
</rss>

