Date / Time Formatting Issue

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Date / Time Formatting Issue

[ Edited ]

I have a date variable that I am trying to report on for a specific range.

 

However, I am having issues tring to get the formatting of the code right.

 

The date format is as follows - DDMONYEAR:00:00:00.000000

 

I have tried the following code -

 

data Quotes;

set test.client

(where= ('15SEP2015:18:00:00.000000'd <= p_created_date <= '25SEP2015:18:00:00.000000'd)

keep= p_created_date

run;

 

Thank you for any and all help Smiley Happy

 

Joshua


Accepted Solutions
Solution
‎12-08-2015 03:13 PM
Grand Advisor
Posts: 10,210

Re: Date / Time Formatting Issue

Looks like a DATETIME value, use DT instead of D for the literal.

View solution in original post


All Replies
Solution
‎12-08-2015 03:13 PM
Grand Advisor
Posts: 10,210

Re: Date / Time Formatting Issue

Looks like a DATETIME value, use DT instead of D for the literal.

Frequent Contributor
Posts: 128

Re: Date / Time Formatting Issue

[ Edited ]

This is a datetime variable according to the format.  Does your data have time stamps associated with the dates?  Or are all the values of the time part of p_created_date equal to 00:00:00?  The where statement is saying that you want any p_created_date between Sept 15, 2015 at 6:00 PM through Sept 25, 2015 at 6:00 PM.  If you are trying to limit it with the 6:00 PM and are having issues (which I would suggest posting what the issues are), I would try eliminating the ".000000" from your datetime ranges and modifying d to dt at the end.  If you are not intending to limit it with the 6:00 PM, I would suggest either changing the 18 to 00 and adding dt instead of d at the end, or just using the datepart() function of p_created_date and removing everything after the 2015 in your limits.

Valued Guide
Posts: 854

Re: Date / Time Formatting Issue

You have to remain consistent with date or datepart. 

 

 

data have;
range1 = '15SEP2015:18:00:00.000000'dt;
range2 = '25SEP2015:18:00:00.000000'dt;
p_create = '20SEP2015:18:00:00.000000'dt;
format range1 range2 p_create datetime25.;
run;


data want;
set have;
if range1 < p_create < range2 then yes = 'yes';
if datepart(range1) < '20sep2015'd < datepart(range2) then check = 'yes';
run;

☑ This topic is SOLVED.

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

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