Help using Base SAS procedures

use date in a select range

Accepted Solution Solved
Reply
Super Contributor
Posts: 396
Accepted Solution

use date in a select range

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


Accepted Solutions
Solution
‎02-22-2017 09:26 AM
Super Contributor
Posts: 396

use date in a select range

[ Edited ]

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


All Replies
Solution
‎02-22-2017 09:26 AM
Super Contributor
Posts: 396

use date in a select range

[ Edited ]

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 ;

 

Valued Guide
Posts: 765

Re: use date in a select range

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 ;


SAS Employee
Posts: 416

Re: use date in a select range

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;

Super Contributor
Posts: 396

Re: use date in a select range

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

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 23227 views
  • 0 likes
  • 3 in conversation