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