BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Astounding
PROC Star

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

 

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

paulkaefer
Lapis Lazuli | Level 10

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

 

 

Reeza
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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