Search code examples
datesasdatastep

How to convert date value from day to Quarter in SAS


I have a data set like this:

date 
01JAN90
01APR90
01JUL90
01OCT90
01JAN91
01APR91
01JUL91
01OCT91

I want to convert the date value into

date
1990Q1
1990Q2
1990Q3
1990Q4
1991Q1
1991Q2
1991Q3
1991Q4

How can I do it in SAS?


Solution

  • Use something like this :

    format date yyq.;
    

    where "date" is your date variable.

    It will do your job.

    Edit: After the datetime7. error, If your date is in character datetime format, first extract the date using datepart and then apply the format on the date.

    sasdate = datepart(date);
    fmtdate = put(sasdate,yyq.);
    

    Here fmtdate is your final answer.

    see here for format yyq.

    see here for datepart

    Hope this finally helps