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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 79514 views
  • 2 likes
  • 3 in conversation