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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates and if/then else 1

Status
Not open for further replies.

STRookie

Technical User
Oct 18, 2010
2
US
Good afternoon,
In a nutshell: we have a date range of 01/01/2011 and 01/31/2011. If the date in the Due date column is in the rnage the new date should be 12/31/2010.
We've tried these three if/then steps so far with no luck:
IF ' 01/01/2011'>=FAKE_DT<= ' 01/31/2011 ' then put ' 12/31/2010'; else

if CE_DUE_DT >= 18628 and CE_DUE_DT <= 18658 then CE_DUE_DT = 18627; else

If 18628 >=FAKE_DT<=18658 then CE_DUE_DT = 18627; else

Basically...the new CE Due Dt needs to be the last day of the previous month.

Can anyone help?
 
If CE_DUE_DT has to always be the last day of the previous month (relative to the date being passed to it), I would recommend using the Intnx function to get the first day of that month and subtract 1 to get the last day of the previous month.

Example
Code:
data _null_ ;
   date = '01SEP10'd ;
   lastDay = intnx('month',date,0,'B')-1 ;
   format date lastday date9. ;
   put _all_ ;
   run ;

Here's a few examples of finding whether a date is in a range (I would suggest putting the dates into variables, or using the 'd to make the code more human readable).

Code:
data _null_ ;
   fromDt = '01SEP10'd ;
   toDt   = '30SEP10'd ;
   dummy  = '15SEP10'd ;
   if fromDt <= dummy <= toDt           then put 'Y';else put 'N' ;
   if dummy >= fromDt and dummy <= toDt then put 'Y';else put 'N' ;
   run;
HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top