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

Hi, any reason why I can use the Date (format YYMMP7.) in a range?  for example I want to select records that fall within  if Date => 2001.01 and Date <= 2011.11

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
podarum
Quartz | Level 8

I got it..  if Date => "01Jan2001"d and Date <= "01Nov2011"d;

 

Shorthand that uses the equality operators but no need for AND:

  

  if  "01Jan2001"d <= Date <= "01Nov2011"d;

 

You could also use WHERE and BETWEEN (it really means between + the two dates) ...

 

where date between "01Jan2001"d and "01Nov2011"d;

 

this also works ...

 

where date between "01Nov2011"d and "01Jan2001"d ;

 

View solution in original post

4 REPLIES 4
podarum
Quartz | Level 8

I got it..  if Date => "01Jan2001"d and Date <= "01Nov2011"d;

 

Shorthand that uses the equality operators but no need for AND:

  

  if  "01Jan2001"d <= Date <= "01Nov2011"d;

 

You could also use WHERE and BETWEEN (it really means between + the two dates) ...

 

where date between "01Jan2001"d and "01Nov2011"d;

 

this also works ...

 

where date between "01Nov2011"d and "01Jan2001"d ;

 

MikeZdeb
Rhodochrosite | Level 12

hi ... if you are using a SAS data set, you could also use WHERE and BETWEEN (it really means between + the two dates) ...

where date between "01Jan2001"d and "01Nov2011"d;

this also works ...

where date between "01Nov2011"d and "01Jan2001"d ;


udo_sas
SAS Employee

Hi -

Just to confirm your understanding:

In SAS, every date is a unique number on a number line. Dates before January 1, 1960, are negative numbers; those after January 1, 1960, are positive.

To write a SAS date constant (in IF or WHERE statements for example), enclose a date in quotation marks in the standard SAS form ddMMMyyyy and immediately follow the final quotation mark with the letter D.

The D suffix tells SAS to convert the calendar date to a SAS date value. Of course you could also use the unformatted numeric value instead.

Example:

data want;

set sashelp.air(where=(date=0)) sashelp.air(where=(date="01JAN1960"d));

run;

podarum
Quartz | Level 8

Thanks Udo, I remembered after I posted it.. but thought there was a different approach with different formats.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 82357 views
  • 2 likes
  • 3 in conversation