BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
6 REPLIES 6
garybald
Calcite | Level 5
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
garybald
Calcite | Level 5
My code got cut off so I changed the symbols to LE.

Message was edited by: garybald Message was edited by: garybald
deleted_user
Not applicable
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
Flip
Fluorite | Level 6
Compare
today() to input(put(yourdtvar, 8.), anydtdte8.)

That should put both in SAS date form.
garybald
Calcite | Level 5
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.
deleted_user
Not applicable
Thank for all your responses, some how dates always stump me in SAS

Shri

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
  • 6 replies
  • 762 views
  • 0 likes
  • 3 in conversation