SAS Dates: Format Quarter as Year / Quarter

I have a dataset with SAS date format "01JAN1980". I want to create a variable called "quarter" with the format "1980Q1" or a combination of year and quarter. Here's what I have my SAS codes: quarter = QRT (date) format quarter yyq.

but it gives me 1960Q1 instead of 1980Q1.

Does anyone know where the problem is?

Thank you so much!

+3


source to share


1 answer


The Quarter function returns the quarter number, which is 1-4. SAS interprets this as a date with a value of 1, which is equivalent to January 1, 1960, and then displays that date in yyq. format. So what you really want is just make a copy of the original without changing the value of the variable and apply the format quarter = date; format quarter yyq.;

.



+3


source







All Articles