<?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 union error: column 2 from the first contributor of UNION... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762670#M241491</link>
    <description>&lt;P&gt;I created the following macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cohort(coh);
	proc sql;
	 create table Cohort&amp;amp;coh as
	  /* readmission */
	  select '_1' as VAR, '0' as CHAR, count(distinct PATID) as CNT from working where not missing(MAECAREI)
	  union
	  select '_1' as VAR, MAECAREI as CHAR, count(distinct PATID) as CNT from working group by MAECAREI
	  union
	  /* any complications */
	  select '_2' as VAR, MAECOMPL as CHAR, count(distinct PATID) as CNT from working group by MAECOMPL
	  union
	  /* death */
	  select '_3' as VAR, MAEDEATH as CHAR, count(distinct PATID) as CNT from working group by MAEDEATH;
	quit;

	*Add ordering for CHAR;
	data Cohort&amp;amp;coh;
	 set Cohort&amp;amp;coh;
	 ORD = cats(VAR, CHAR); /*combine two columns*/
	run;

	*Calculate percentages;
	data Cohort&amp;amp;coh;
	 set Cohort&amp;amp;coh;
	 if (100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh) &amp;gt;= 1 then PCT = put(100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh, 3.);
	 else if 0 &amp;lt; (100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh) &amp;lt; 1 then PCT = '&amp;lt;1';
	 else PCT = '-';
	run;
%mend;&lt;BR /&gt;&lt;BR /&gt;%cohort(coh = A); %cohort(coh = B);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And receive the following error in my log file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Column 2 from the first contributor of UNION is not the same type as its counterpart from
       the second.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would assume this means that my columns in PROC SQL are not labeled the same or in the same order. However, that is not how it appears to me. What are the possible issues and solutions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complete log file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1629402421099.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62745i570FEF7DB21EF9FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1629402421099.png" alt="mariko5797_0-1629402421099.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 19:48:56 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2021-08-19T19:48:56Z</dc:date>
    <item>
      <title>PROC SQL union error: column 2 from the first contributor of UNION...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762670#M241491</link>
      <description>&lt;P&gt;I created the following macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cohort(coh);
	proc sql;
	 create table Cohort&amp;amp;coh as
	  /* readmission */
	  select '_1' as VAR, '0' as CHAR, count(distinct PATID) as CNT from working where not missing(MAECAREI)
	  union
	  select '_1' as VAR, MAECAREI as CHAR, count(distinct PATID) as CNT from working group by MAECAREI
	  union
	  /* any complications */
	  select '_2' as VAR, MAECOMPL as CHAR, count(distinct PATID) as CNT from working group by MAECOMPL
	  union
	  /* death */
	  select '_3' as VAR, MAEDEATH as CHAR, count(distinct PATID) as CNT from working group by MAEDEATH;
	quit;

	*Add ordering for CHAR;
	data Cohort&amp;amp;coh;
	 set Cohort&amp;amp;coh;
	 ORD = cats(VAR, CHAR); /*combine two columns*/
	run;

	*Calculate percentages;
	data Cohort&amp;amp;coh;
	 set Cohort&amp;amp;coh;
	 if (100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh) &amp;gt;= 1 then PCT = put(100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh, 3.);
	 else if 0 &amp;lt; (100*CNT/&amp;amp;&amp;amp;tot_&amp;amp;coh) &amp;lt; 1 then PCT = '&amp;lt;1';
	 else PCT = '-';
	run;
%mend;&lt;BR /&gt;&lt;BR /&gt;%cohort(coh = A); %cohort(coh = B);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And receive the following error in my log file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Column 2 from the first contributor of UNION is not the same type as its counterpart from
       the second.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would assume this means that my columns in PROC SQL are not labeled the same or in the same order. However, that is not how it appears to me. What are the possible issues and solutions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complete log file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1629402421099.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62745i570FEF7DB21EF9FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1629402421099.png" alt="mariko5797_0-1629402421099.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 19:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762670#M241491</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-08-19T19:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL union error: column 2 from the first contributor of UNION...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762677#M241495</link>
      <description>&lt;P&gt;Do a PROC CONTENTS of "&lt;EM&gt;&lt;FONT face="andale mono,times"&gt;working&lt;/FONT&gt;&lt;/EM&gt;", please.&amp;nbsp; If it's big, put emphasis on&amp;nbsp; "&lt;EM&gt;&lt;FONT face="andale mono,times"&gt;MAE&lt;/FONT&gt;&lt;/EM&gt;:", "&lt;EM&gt;&lt;FONT face="andale mono,times"&gt;MAECAREI&lt;/FONT&gt;&lt;/EM&gt;", "&lt;EM&gt;&lt;FONT face="andale mono,times"&gt;MAECOMPL&lt;/FONT&gt;&lt;/EM&gt;", etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 20:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762677#M241495</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-08-19T20:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL union error: column 2 from the first contributor of UNION...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762680#M241496</link>
      <description>&lt;P&gt;I think the problem is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select '_1' as VAR, &lt;STRONG&gt;'0' as CHAR&lt;/STRONG&gt;, count(distinct PATID) as CNT from working where not missing(MAECAREI)
union
select '_1' as VAR, &lt;STRONG&gt;MAECAREI as CHAR&lt;/STRONG&gt;, count(distinct PATID) as CNT from working group by MAECAREI
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the first select created the value for the column named CHAR as '0', this is a character value.&amp;nbsp;From the error, it appears that MAECAREI is a numeric value. YOu can't "stack" a numeric value in a character column. Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select '_1' as VAR, &lt;STRONG&gt;0 as CHAR&lt;/STRONG&gt;, count(distinct PATID) as CNT from working where not missing(MAECAREI)
union
select '_1' as VAR, MAECAREI as CHAR, count(distinct PATID) as CNT from working group by MAECAREI&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Aug 2021 20:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-union-error-column-2-from-the-first-contributor-of/m-p/762680#M241496</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-08-19T20:09:31Z</dc:date>
    </item>
  </channel>
</rss>

