Elif Y
Elif Y

Reputation: 251

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?

Upvotes: 2

Views: 11453

Answers (2)

PKumar
PKumar

Reputation: 11128

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

Upvotes: 2

Reeza
Reeza

Reputation: 21274

For a new character variable:

 quarter = put(date, yyq.);

To format the same variable which is all you usually need:

format date yyq.;

EDIT: To convert a character date to a SAS date use the following: sas_date=input(date, anydtdte.);

Upvotes: 0

Related Questions