Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract based on Date range condition 1

Status
Not open for further replies.

irinnew

Technical User
Mar 19, 2005
81
US
Hi!
My data looks like : start_date 04feb2004
End_daye 15mar2005

I need to extract those records within 01jan2004 and 15apr2005 date range

DATA myfile;
Enroll =datepart(Start_Date)-datepart(End_Date);
if '01jan04'd le Enroll le '15apr05'd then output enrollyes;
else output enrollno;
run;

I have 0 observations however! Although there is a lot of them by all means…

What am I doing wrong?

Thans,

Irin
 
Irinnew,

Datepart is a function that is used to extract the date from a datetime variable. In this case you dont use the datepart function but a standard input function.
(I am presuming that in the start_date var the date looks like 04feb2004 and not "start_date 04feb2004" as a string.)

ex.
Code:
DATA enrollyes enrollno;
  set myfile;
  if start_date ge '01jan04'd and
     end_date le '15apr05'd then 
     output enrollyes; 
  else
     output enrollno; 
run;

I hope that this helps you.
Klaz
 
Klaz,

Thank you,I did eliminated datepart function and my
code generates two datasets

However for some reason Enrollyes is empty while EnrollNo contains even those who are between 01jan04 and 15apr05 and who I would expect to see in Enrollyes:-(

For ex, EnrollNo contains Start_date 01feb2004 and end_date 20mar2005 although this range is within 01jan04 and 15apr05 date range….

Proc content shows:

-----Alphabetic List of Variables and Attributes-----

# Variable Type Len Pos Format Informat Label

End_Date Num 8 16 DATETIME20. DATETIME20. End_Date
Start_Date Num 8 8 DATETIME20. DATETIME20. Start_Date


So…I am confused …. What is wrong?
 
Ok according to the proc contents the start_date & end_date variables are in datetime format. You do need to use the datepart() function. Try this code again with the minor change.

Code:
DATA enrollyes enrollno;
  set myfile;
  if datepart(start_date) ge '01jan04'd and
     datepart(end_date) le '15apr05'd then 
     output enrollyes; 
  else
     output enrollno; 
run;

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top