Help using Base SAS procedures

Date range question

Reply
N/A
Posts: 0

Date range question

Hello All,
I am having a little trouble in figuring this out, may be you can provide some insight.
I have a dataset which has range of dates grouped as ranges.

eg. range1 8/25/09 - 9/22/09(all dates inclusive) 8
range2 9/26/09 - 10/21/09 10
-
range 6 12/29/09 - 1/19/10 5
range 7 1/20/10 - 2/20/10 6

and so on
my problem is I have to find in which range does today's fall under (in this example range 7). Once I find the range, I need the data for the previous range (in my example range6) Each range has a no. of obsevations associated with it as shown above. I want my output to be

range 6 12/29/09 - 1/19/10 5

Any help is greatly appreciated.

Thanks
Shri
Contributor
Posts: 29

Re: Date range question

Posted in reply to deleted_user
I read the entire line in as a character string, and used list input to get each part separately so I had the dates.

data temp;
input @1 x $40.
@1 range $7.
date1 mmddyy8.
hyphen $1.
date2 mmddyy8.
obser 2.;
cards;
range1 8/25/09 - 9/22/09 8
range2 9/26/09 - 10/21/09 10
range6 12/29/09 - 1-19/10 5
range7 1/20/10 - 2/20/10 6
;
run;
data temp;
set temp;
y = lag(x);
if date1 LE today() LE date2 then output;
run;
proc print;
var y;
run;
Message was edited by: garybald

Message was edited by: garybald

Message was edited by: garybald Message was edited by: garybald
Contributor
Posts: 29

Re: Date range question

My code got cut off so I changed the symbols to LE.

Message was edited by: garybald Message was edited by: garybald
N/A
Posts: 0

Re: Date range question

Garybald,
Thank you for your email. I have the dates for the range as separate fields. But they are stored as numbers (like 20090801), both for the start date of the range and the end date of the range. My problem was when I use today() the ourput is a sasdate (number of days), so I don't know how to compare the date stored as numbers and the date which is number of days.

Here is how I have the data

range startdate enddate
range1 20090801 20090901
range2 20090902 20090930


range6 20100107 20100211
range7 20100212 20100310

and so on

when I use the date function I get the output as a number
date() for today 18312

Can you help me compare these dates which are stored in different formats.

Thanks
Super Contributor
Posts: 359

Re: Date range question

Posted in reply to deleted_user
Compare
today() to input(put(yourdtvar, 8.), anydtdte8.)

That should put both in SAS date form.
Contributor
Posts: 29

Re: Date range question

Posted in reply to deleted_user
Instead of reading the date in as mmddyy8. that your original post showed, use the informat to read it in as yymmdd8. which will interpret and convert the number internally to a SAS date, so the today() will work. Just make sure that when you write the data out, use a format, so it doesn't write it out as a SAS date. If you use yymmddn8. the separators will be removed, and you will have your original number.
N/A
Posts: 0

Re: Date range question

Thank for all your responses, some how dates always stump me in SAS

Shri
Ask a Question
Discussion stats
  • 6 replies
  • 174 views
  • 0 likes
  • 3 in conversation