BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi,

I have a problem on checking date range, consider below dataset layout

N Date1 Date2 Value
1 21Jan2009 22Feb2009 5
2 21Jan2009 22Mar2009 6
3 21May2009 22Nov2009 9
4 21Oct2009 22Oct2009 34
5 21Jan2009 22June2009 6

I want to select entries with the dates fall in October 2009
(ie, outcome is record #3,#4 is being selected)

any efficient way to compile this??

Many thanks
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
I'm not sure what you mean by selecting entries...do you want a report (such as from PROC PRINT) or a dataset (such as from PROC SQL)???

If all you want is a report, you could use a WHERE clause in PROC PRINT. Something like this (assumes that date1 and date2 are numeric variables in the SAS dataset):
[pre]
proc print data=lib.data;
title 'Use WHERE clause for selection';
where 10 between month(date1) and month(date2) and
(year(date1)=2009 or year(date2)=2009);
format date1 date2 mmddyy10.;
run;
[/pre]

If the WHERE statement selects the observations you want in the PROC PRINT, then you could use the same WHERE logic in a PROC SQL query to create a dataset. If you know your data are all from 2009, then you don't need the check for year.

cynthia
deleted_user
Not applicable
thx cythnia!!

actually, proc print or data selection is okay, the dataset may be like this

N Date1 Date2 Value
1 21Jan2009 22Feb2009 5
2 21Jan2009 22Mar2009 6
3 21May2009 22Nov2009 9 *
4 21Oct2009 22Oct2009 34 *
5 21Jan2009 22June2009 6
6 3 Mar 2005 22Oct2009 3 *
7 3 Mar 2007 31Dec2999 2 *

then i want to select records with any dates in October 2009 fall into Date 1 and Date2
after i rethink about this scenario, i think

if date1 <= '31oct2009'd and date2 >= '1oct2009'd

may solve the problem

btw, any sas function can cater this scenairo?

Thanks again
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS function INTNX can be used to test a SAS variable or constant against a SAS literal (or another SAS variable) as you might need -- using the test you performed for '01OCT2009'd. Check the SAS DOC on this function - also there will be sample code content and technical/conference papers using the function on the SAS.COM website.

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1212 views
  • 0 likes
  • 3 in conversation