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

Hi everyone,

 

I have a problem filtering a date based on the format new_date monyy5.; 

 

I have variables that have that format and I want to pull the data based on the month that they land on. 

 

I tired to do something like this 

 

data X;
set Y;
where new_date='SEP19'd; 
run;

 

keeps telling me that I have an invalid date/time/datetime constant - why is that? 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You're changing the question on me here.

You initially stated you had a date variable with monyy format.
Now you have a datetime?

What do you have and what do you want to do?

Dates are not datetimes and vice versa and needed to be treated differently. Also, you specify datetimes with a DT at the end, not a D.

Common literals are:

D - Date
DT - Datetime
N - Named variable or dataset

View solution in original post

5 REPLIES 5
Reeza
Super User

Because you need to use the underlying value, not the formatted value. 

Or convert to the formatted value.

 

data X;
set Y;
where put(new_date, monyy5.)='SEP19'; 
run;

@sasxii wrote:

Hi everyone,

 

I have a problem filtering a date based on the format new_date monyy5.; 

 

I have variables that have that format and I want to pull the data based on the month that they land on. 

 

I tired to do something like this 

 

data X;
set Y;
where new_date='SEP19'd; 
run;

 

keeps telling me that I have an invalid date/time/datetime constant - why is that? 


 

sasxii
Calcite | Level 5

underlying value? 

Reeza
Super User
The unformatted value.
sasxii
Calcite | Level 5

so I tried using that as well which was a datetime. format - which consisted of 

 

data X;
set Y;
if DATE >= '01SEP19:20:55:00'd and DATE <= '30SEP19:20:55:00'd;
run;

 

and it doesnt pull up anything, why would that be the case? 

Reeza
Super User
You're changing the question on me here.

You initially stated you had a date variable with monyy format.
Now you have a datetime?

What do you have and what do you want to do?

Dates are not datetimes and vice versa and needed to be treated differently. Also, you specify datetimes with a DT at the end, not a D.

Common literals are:

D - Date
DT - Datetime
N - Named variable or dataset

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2011 views
  • 0 likes
  • 2 in conversation