Help using Base SAS procedures

PROC SQL error data types

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 123
Accepted Solution

PROC SQL error data types

[ Edited ]

I have the following queries:

 

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;

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.

 

Thanks in advance,

JediApprentice


ProcContents.PNG

Accepted Solutions
Solution
‎06-21-2016 06:23 PM
Respected Advisor
Posts: 4,641

Re: PROC SQL error data types

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.

PG

View solution in original post


All Replies
Solution
‎06-21-2016 06:23 PM
Respected Advisor
Posts: 4,641

Re: PROC SQL error data types

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.

PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 276 views
  • 0 likes
  • 2 in conversation