DATA Step, Macro, Functions and more

Disparate Date Types

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 123
Accepted Solution

Disparate Date Types

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;

Accepted Solutions
Solution
‎06-22-2016 06:08 PM
Super User
Posts: 17,818

Re: Disparate Date Types

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.

View solution in original post


All Replies
Super User
Posts: 5,081

Re: Disparate Date Types

You'll have to make the BETWEEN values match the values for FilledMonth, possibly:

 

where (FilledMonth between '2015M01' and '2015M12') ...

Regular Contributor
Posts: 159

Re: Disparate Date Types

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).

 

 

Solution
‎06-22-2016 06:08 PM
Super User
Posts: 17,818

Re: Disparate Date Types

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.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 338 views
  • 1 like
  • 4 in conversation