I want to write a code to add a variable say 'Month' such that if the Date is between 1/10/2002 to 31/10/2009 then month = month1 and if Date is between 1/11/2002 to 30/11/2009 then month = month2; if the Date is between 1/12/2001 to 31/11/2009 then month = month3.
As previously explained, it is hard to do comparisons with dates that are character strings. Your best bet is to turn your character DATE variable into a SAS date value and then use DATA step logic to create your new variables.
You say you want:
month = month1;
month = month2;
month = month3;
but, could you want:
month = 'month1';
month = 'month2';
month = 'month3';
Are MONTH1, MONTH2 and MONTH3 variables or are you trying to create a character variable MONTH, whose values will be the text strings "MONTH1", "MONTH2" and "MONTH3"??? It makes a difference in the code whether MONTH will be character or numeric and whether MONTH1, MONTH2 and MONTH3 are variables or the values you want to assign.
so, you should be able to turn your character DATE into a SAS date, with syntax similar to this:
sasdate = input(DATE,ddmmyy10.);
And then you should be able to simply do this, utilizing the MONTH function (and assigning a text string to the MONTH variable):
if month(SASDATE) = 10 then month = "month1";
else if month(SASDATE) = 11 then month = "month2";
else if month(SASDATE) = 12 then month = "month3";
Note that I did NOT use your full date values in the comparison. Why not? Your ranges and logical conditions do NOT make sense to me.
Your first range is from Oct 1, 2002 thru October 31, 2009 and then your second range is from Nov 1, 2002 thru Nov 30, 2009. And then your THIRD range is from Dec 1, 2001 to Nov 31, 2009 (Nov 31 is an invalid date). But Nov 1, 2002 would fall into the first range and a date of Nov 29, 2009 would fall into the second range -AND- the third range. And, since the ending date for your third range is an invalid date (31/11/2009), some further clarification is needed on your part about what you ACTUALLY want and what your date ranges are.
As previously explained, if I wanted to test whether a particular SAS date variable value needed to be compared to a SPECIFIC date value, I would have to provide a DATE constant or a numeric value for date for purposes of the comparison.
You will get more (and more on-point) help, if you can post the code that you've tried and show the error messages or explain the problems you've encountered. There is a previous forum posting that explains how to post code that contains < and > symbols or <= and >= symbols. That forum posting is here: http://support.sas.com/forums/thread.jspa?threadID=7550