You can use the INTCK () function (SAS speak for Intervals - count number of) to calculate the number of quarters from the base date. However, to use the function you need to convert your 'date' into a SAS date within the quarter. Something like this should do: Data want; Set have ; By id ; /* assuming you have an id to group your data and the data is sorted by the id */ Retain Basedate ; Format SASdate Startdate ddmmyy10. ; /* mmddyy10 if you prefer */ Year = INT(date) ; If first.id then Startdate = mdy (1, 1, Year) - 1 ; /* Prev 31 Dec */ Month = 30 * (date - Year) ; /* values 3, 6, 9 etc */ SASdate = mdy(Month, 1, Year) ; Quarter = INTCK ('QTR', Startdate, SASdate) ; Drop Year Month ; Run ; If your date variable is character then Year = Input (date, 4.) ; Month = Input (Scan (date, -1, '.'), 1.) * 3 ; If you have no id variable and all the quarters are calculated from the first record then delete the By ... statement and replace the If ... statement with If _N_ = 1 then Startdate = mdy (1, 1, Year) - 1 ; /* Prev 31 Dec */ Richard Message was edited by: Richard Carson - mismatched quotes in the Quarter = expression.
... View more