<?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: Union issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230769#M41909</link>
    <description>&lt;P&gt;I see nothing wrong with the syntax. Maybe something wrong happened before in the session. Try starting a new SAS session, if you can, and resubmit the query.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Oct 2015 15:09:06 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-10-20T15:09:06Z</dc:date>
    <item>
      <title>Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230750#M41899</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new with SAS and running below query in SAS editor and getting error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: ), ',', ANSIMISS, CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN, LEFT, NATURAL, NOMISS, OUTER, RIGHT, UNION, WHERE&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am running below query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname mydblib oracle user=ABCD password=A12345 path=msrprod2 schema=MCA;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table brand as&lt;BR /&gt;select PROD,IND_ID from (&lt;BR /&gt;select 'DR' as PROD,IND_ID AS IND_ID&lt;BR /&gt;FROM UNIC.DR&lt;BR /&gt;UNION&lt;BR /&gt;select 'HF' as PROD,IND_ID AS IND_ID&lt;BR /&gt;FROM UNIC.HF&lt;/P&gt;&lt;P&gt;UNION&lt;BR /&gt;select 'ROH' as PROD,IND_ID AS IND_ID&lt;BR /&gt;FROM UNIC.ROH&lt;/P&gt;&lt;P&gt;UNION&lt;BR /&gt;select 'NBB' as PROD,IND_ID AS IND_ID&lt;BR /&gt;FROM UNIC.NBB&lt;/P&gt;&lt;P&gt;UNION&lt;BR /&gt;select 'EMR' as PROD,IND_ID AS IND_ID&lt;BR /&gt;FROM UNIC.EMR);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please let me know what is the correct way&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 14:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230750#M41899</guid>
      <dc:creator>CG1</dc:creator>
      <dc:date>2015-10-20T14:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230764#M41904</link>
      <description>&lt;P&gt;Hi friend,&lt;/P&gt;
&lt;P&gt;I'm not an expert in SQL but, in my guess i would say to close with "()" in each "select" or use the except option between them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A title="Proc SQL - Combining Queries with Set Operators" href="http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001361224.htm" target="_self"&gt;Proc SQL - Combining Queries with Set Operators&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Att&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 15:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230764#M41904</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-20T15:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230765#M41905</link>
      <description>&lt;P&gt;Can't see any&amp;nbsp;problem in your code. Are you sure that's the exact code you are submitting?&lt;/P&gt;&lt;P&gt;Please post the complete log including the submitted code part.&lt;/P&gt;&lt;P&gt;If you are not sure about the syntax, try the same with a sample SASHELP table, I got it to work.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 15:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230765#M41905</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-20T15:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230769#M41909</link>
      <description>&lt;P&gt;I see nothing wrong with the syntax. Maybe something wrong happened before in the session. Try starting a new SAS session, if you can, and resubmit the query.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 15:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230769#M41909</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-20T15:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230860#M41933</link>
      <description>Another test you might try to do to verify is to run the individual subqueries individually, one at a time, and then try a union and then have the higher query to select the 2 columns. I'd try this way step by step, so you know where the issue is... As the previous respondents indicated, if you can post the entire log, it will help see better.   Good luck anyway...!</description>
      <pubDate>Wed, 21 Oct 2015 03:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230860#M41933</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-10-21T03:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230893#M41947</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still getting the same error. Please help&lt;/P&gt;&lt;P&gt;Below is the complete log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;81&amp;nbsp;&amp;nbsp; libname mydblib oracle user=ABCD password=A12345 path=msrprod2 schema=MCA;&lt;/P&gt;&lt;P&gt;NOTE: Libref MYDBLIB was successfully assigned as follows:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Engine:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORACLE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Physical Name: msrprod2&lt;BR /&gt;82&amp;nbsp;&amp;nbsp; proc sql;&lt;BR /&gt;83&amp;nbsp;&amp;nbsp; create table brand&amp;nbsp; as&lt;BR /&gt;84&amp;nbsp;&amp;nbsp; select PROD,IND_ID from (&lt;BR /&gt;85&amp;nbsp;&amp;nbsp; select 'DR' as PROD,IND_ID AS IND_ID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---------&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;86&amp;nbsp;&amp;nbsp; FROM UNIC.DR&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, (, ), ',', '.', ANSIMISS, AS, CROSS, EXCEPT, FULL, GROUP,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS, OUTER, RIGHT, UNION, WHERE.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;87&amp;nbsp;&amp;nbsp; UNION&lt;BR /&gt;88&amp;nbsp;&amp;nbsp; select 'HF' PROD_ABBR,INDIVIDUAL_ID_ID&lt;BR /&gt;89&amp;nbsp;&amp;nbsp; FROM UNICARUNUS.HF&lt;BR /&gt;90&amp;nbsp;&amp;nbsp; UNION&lt;BR /&gt;91&amp;nbsp;&amp;nbsp; select 'ROH' PROD_ABBR,INDIVIDUAL_ID_ID&lt;BR /&gt;92&amp;nbsp;&amp;nbsp; FROM UNICARUNUS.ROH&lt;BR /&gt;93&amp;nbsp;&amp;nbsp; UNION&lt;BR /&gt;94&amp;nbsp;&amp;nbsp; select 'NBB' PROD_ABBR,INDIVIDUAL_ID_ID&lt;BR /&gt;95&amp;nbsp;&amp;nbsp; FROM UNICARUNUS.NBB&lt;BR /&gt;96&amp;nbsp;&amp;nbsp; UNION&lt;BR /&gt;97&amp;nbsp;&amp;nbsp; select 'EMR' PROD_ABBR,INDIVIDUAL_ID_ID&lt;BR /&gt;98&amp;nbsp;&amp;nbsp; FROM UNICARUNUS.EMR);&lt;BR /&gt;99&amp;nbsp;&amp;nbsp; 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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.03 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.03 seconds&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 11:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230893#M41947</guid>
      <dc:creator>CG1</dc:creator>
      <dc:date>2015-10-21T11:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Union issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230896#M41948</link>
      <description>&lt;P&gt;Thanks for posting the log. &amp;nbsp;Would you mind trying a couple of things please. This should just take a minute.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Can you try running the individual select statements within the subquery as stand-alone to ensure they run fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Combine 2 queries with a union; if it works include the rest with union as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Try to enclose each select query within parantheses that are joined by the Union.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) Include all queries within a high level parantheses and then bring in the wrapper query where you select the data from the result of the union.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should hopefully point out the exact location of the issue. Please post the log if you can, Thanks and good luck my friend...!!!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 11:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-issue/m-p/230896#M41948</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-10-21T11:53:50Z</dc:date>
    </item>
  </channel>
</rss>

