I have a where clause that looks like this:
WHERE (FilledMonth BETWEEN '01jan2015'd AND '31dec2015'd) AND CLIENT = 'BCBS NC';
The variable FilledMonth is character and it has a format of $7. In the data it looks like: 2015M01. However, when I run it, I get an error related to the different data types of FilledMonth and the date literals. Is there a way around this?
The error message: "Expression using IN has components that are of different data types."
The full query is here:
PROC SQL; CREATE TABLE EGTASK.NC_SAVINGS AS SELECT t1.FilledMonth, t1.Client, t1.Business_Line, t1.Segment, t1.MACSavingsGrouping AS Channel, t1.Specialty_Flag, t1.BRAND_GENERIC, t1.ApprovedPriceType, t1.SUM_OF_AWP, t1.SUM_OF_APPROVEDINGREDIENTCOST, t1.SUM_OF_ADFA, t1.SUM_OF_RX FROM EGTASK.All_Combined_Table t1 WHERE (FilledMonth BETWEEN '01jan2015'd AND '31dec2015'd) AND CLIENT = 'BCBS NC'; QUIT;
As indicated in your other question here https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Date-Range/m-p/279473#M58987
You need to find the correct format.
In this case it's yymm7.
WHERE (INPUT(FilledMonth, yymm7.) BETWEEN '01jan2015'd AND '31dec2015'd)
If you want your date variables to be actual dates convert them to dates, don't store them as character variables.
You'll have to make the BETWEEN values match the values for FilledMonth, possibly:
where (FilledMonth between '2015M01' and '2015M12') ...
This seems to be because your FilledMonth data is a character format, but you're comparing to dates.
Try something like a modified version of what is suggested in this post:
select input(trim(FilledMonth), MMDDYY10.) as FilledMonth_dateFmt
The other comments in that thread discuss different ways to get rid of extra space (your FilledMonth variable may be longer than just seven characters wide).
As indicated in your other question here https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Date-Range/m-p/279473#M58987
You need to find the correct format.
In this case it's yymm7.
WHERE (INPUT(FilledMonth, yymm7.) BETWEEN '01jan2015'd AND '31dec2015'd)
If you want your date variables to be actual dates convert them to dates, don't store them as character variables.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.