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

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 🙂

 

Joshua

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

View solution in original post

3 REPLIES 3
ballardw
Super User

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

dcruik
Lapis Lazuli | Level 10

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.

Steelers_In_DC
Barite | Level 11

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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