SAS dates: format the quarter as year/quarter

12,436

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

Also, in some cases you might not even need to make a copy of the variable - you can place a format statement in the middle of most procs and it will use that format for the output of the proc.

Share:
12,436
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a data set with SAS date format "01JAN1980". I want to generate a variable called "quarter" with format "1980Q1" or what ever combination of year and quarter. Here is what I my SAS codes: quarter=QRT(date) format quarter yyq.

    but it gives me 1960Q1 instead of 1980Q1.

    Does any one know where is the problem?

    Thanks very much!!!