<?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 error data types in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-error-data-types/m-p/279156#M58972</link>
    <description>&lt;P&gt;I have the following queries:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE GROUP_SAVINGS_Prep AS
  SELECT t1.COMPOUNDCODE,
         t1.NETWORK,
         t1.FilledMonth,
		 t1.MACSavingsGrouping AS Channel,
		 t1.BRAND_GENERIC,
		 t1.EXCLUSIONS,
		 t1.GroupPlanCode,
		 t1.MAC_Flag,
		 t1.Specialty_Flag,
		 t1.SERVICEPROVIDERID,
		 t1.SUM_OF_RX,
		 t1.SUM_OF_AWP,
		 t1.ApprovedIngredientCost,
		 t1.ApprovedDispensingFeeAmount
  FROM EGTASK.All_Combined_Table t1
  WHERE t1.Specialty_Flag = 'Non-Specialty' AND t1.COMPOUNDCODE ne '2' AND t1.MACSavingsGrouping ne 'MAIL' AND t1.EXCLUSIONS = 'NA'
        AND t1.GroupPlanCode IN('NEC7729','NEC7621','NEC7620');
QUIT;

PROC SQL;
CREATE TABLE GROUP_SAVINGS_PREP2 AS
SELECT t1.COMPOUNDCODE,
       t1.NETWORK,
       t1.FilledMonth,
       t1.Channel,
       t1.BRAND_GENERIC,
       t1.EXCLUSIONS,
       t1.GroupPlanCode,
       t1.MAC_Flag,
       t1.Specialty_Flag,
       t1.SERVICEPROVIDERID,
       t1.SUM_OF_RX,
       t1.SUM_OF_AWP,
       t1.ApprovedIngredientCost,
       t1.ApprovedDispensingFeeAmount,
	   t2.Brand_Discount,
	   t2.Brand_Dispense_Fee,
	   t2.Generic_Discount,
	   t2.Generic_Dispense_Fee
FROM WORK.GROUP_SAVINGS_Prep t1
INNER JOIN EGTASK.'PTSLCT _ 2016_06_17_0000'n t2 ON (input(t1.SERVICEPROVIDERID,15.) = t2.NCPDP);
QUIT;

PROC SQL;
CREATE TABLE GROUP_SAVINGS AS
SELECT t1.Brand_Dispense_Fee,
       t1.COMPOUNDCODE,
       t1.NETWORK,
       t1.FilledMonth,
       t1.Channel,
       t1.BRAND_GENERIC,
       t1.EXCLUSIONS,
       t1.GroupPlanCode,
       t1.MAC_Flag,
       t1.Specialty_Flag,
       t1.SERVICEPROVIDERID,
       t1.SUM_OF_RX,
       t1.SUM_OF_AWP,
       t1.ApprovedIngredientCost,
       t1.ApprovedDispensingFeeAmount,
	   /* New AWP Rate field */
	   (CASE
	      WHEN t1.Channel = 'Retail' and t1.BRAND_GENERIC = 'Brand' and t1.MAC_Flag = 'AWP' then t1.Brand_Discount
		  WHEN t1.Channel = 'ESN' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then '.1897'
		  WHEN t1.Channel = 'Retail' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then t1.Generic_Discount
		  WHEN t1.Channel = 'ESN' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then '.3'
          ELSE (t1.SUM_OF_AWP - t1.ApprovedIngredientCost)/t1.SUM_OF_AWP
	    END) AS AWP_RATE_NEW, 
       /* New Dispensing Fee field */
	   (CASE
	      WHEN t1.CHannel = 'Retail' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then t1.Brand_Dispense_Fee
		  WHEN t1.CHannel = 'ESN' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then '0'
          WHEN t1.CHannel = 'Retail' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then t1.Generic_Dispense_Fee
		  WHEN t1.CHannel = 'ESN' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then '0'
		  ELSE t1.ApprovedDispensingFeeAmount/SUM_OF_RX
		END) AS DISP_FEE_NEW
FROM GROUP_SAVINGS_PREP2 t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When it hits the third query, I get an error: "Result of WHEN clause 2 is not the same data type as the preceding results." Is this something that can be solved using an input function? Or some other way to make the data types the same? I've attached a screenshot of the proc contents of the input data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;JediApprentice&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12682i052C9E949921D7EB/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="ProcContents.PNG" title="ProcContents.PNG" /&gt;</description>
    <pubDate>Tue, 21 Jun 2016 20:53:03 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-06-21T20:53:03Z</dc:date>
    <item>
      <title>PROC SQL error data types</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-error-data-types/m-p/279156#M58972</link>
      <description>&lt;P&gt;I have the following queries:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE GROUP_SAVINGS_Prep AS
  SELECT t1.COMPOUNDCODE,
         t1.NETWORK,
         t1.FilledMonth,
		 t1.MACSavingsGrouping AS Channel,
		 t1.BRAND_GENERIC,
		 t1.EXCLUSIONS,
		 t1.GroupPlanCode,
		 t1.MAC_Flag,
		 t1.Specialty_Flag,
		 t1.SERVICEPROVIDERID,
		 t1.SUM_OF_RX,
		 t1.SUM_OF_AWP,
		 t1.ApprovedIngredientCost,
		 t1.ApprovedDispensingFeeAmount
  FROM EGTASK.All_Combined_Table t1
  WHERE t1.Specialty_Flag = 'Non-Specialty' AND t1.COMPOUNDCODE ne '2' AND t1.MACSavingsGrouping ne 'MAIL' AND t1.EXCLUSIONS = 'NA'
        AND t1.GroupPlanCode IN('NEC7729','NEC7621','NEC7620');
QUIT;

PROC SQL;
CREATE TABLE GROUP_SAVINGS_PREP2 AS
SELECT t1.COMPOUNDCODE,
       t1.NETWORK,
       t1.FilledMonth,
       t1.Channel,
       t1.BRAND_GENERIC,
       t1.EXCLUSIONS,
       t1.GroupPlanCode,
       t1.MAC_Flag,
       t1.Specialty_Flag,
       t1.SERVICEPROVIDERID,
       t1.SUM_OF_RX,
       t1.SUM_OF_AWP,
       t1.ApprovedIngredientCost,
       t1.ApprovedDispensingFeeAmount,
	   t2.Brand_Discount,
	   t2.Brand_Dispense_Fee,
	   t2.Generic_Discount,
	   t2.Generic_Dispense_Fee
FROM WORK.GROUP_SAVINGS_Prep t1
INNER JOIN EGTASK.'PTSLCT _ 2016_06_17_0000'n t2 ON (input(t1.SERVICEPROVIDERID,15.) = t2.NCPDP);
QUIT;

PROC SQL;
CREATE TABLE GROUP_SAVINGS AS
SELECT t1.Brand_Dispense_Fee,
       t1.COMPOUNDCODE,
       t1.NETWORK,
       t1.FilledMonth,
       t1.Channel,
       t1.BRAND_GENERIC,
       t1.EXCLUSIONS,
       t1.GroupPlanCode,
       t1.MAC_Flag,
       t1.Specialty_Flag,
       t1.SERVICEPROVIDERID,
       t1.SUM_OF_RX,
       t1.SUM_OF_AWP,
       t1.ApprovedIngredientCost,
       t1.ApprovedDispensingFeeAmount,
	   /* New AWP Rate field */
	   (CASE
	      WHEN t1.Channel = 'Retail' and t1.BRAND_GENERIC = 'Brand' and t1.MAC_Flag = 'AWP' then t1.Brand_Discount
		  WHEN t1.Channel = 'ESN' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then '.1897'
		  WHEN t1.Channel = 'Retail' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then t1.Generic_Discount
		  WHEN t1.Channel = 'ESN' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then '.3'
          ELSE (t1.SUM_OF_AWP - t1.ApprovedIngredientCost)/t1.SUM_OF_AWP
	    END) AS AWP_RATE_NEW, 
       /* New Dispensing Fee field */
	   (CASE
	      WHEN t1.CHannel = 'Retail' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then t1.Brand_Dispense_Fee
		  WHEN t1.CHannel = 'ESN' and t1.Brand_Generic = 'Brand' and t1.MAC_Flag= 'AWP' then '0'
          WHEN t1.CHannel = 'Retail' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then t1.Generic_Dispense_Fee
		  WHEN t1.CHannel = 'ESN' and t1.Brand_Generic = 'Generic' and t1.MAC_Flag= 'NON-MAC' then '0'
		  ELSE t1.ApprovedDispensingFeeAmount/SUM_OF_RX
		END) AS DISP_FEE_NEW
FROM GROUP_SAVINGS_PREP2 t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When it hits the third query, I get an error: "Result of WHEN clause 2 is not the same data type as the preceding results." Is this something that can be solved using an input function? Or some other way to make the data types the same? I've attached a screenshot of the proc contents of the input data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;JediApprentice&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12682i052C9E949921D7EB/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="ProcContents.PNG" title="ProcContents.PNG" /&gt;</description>
      <pubDate>Tue, 21 Jun 2016 20:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-error-data-types/m-p/279156#M58972</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-06-21T20:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL error data types</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-error-data-types/m-p/279166#M58974</link>
      <description>&lt;P&gt;Fields such as Brand_discount are numeric and quoted numbers such as '.1897' are character. Remove the quotes to make all alternatives the same type.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 21:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-error-data-types/m-p/279166#M58974</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-21T21:44:18Z</dc:date>
    </item>
  </channel>
</rss>

