Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struggling with dates formats, want YYYY-MM-DD

Tags:

date

sas

As an absolute beginner to SAS I quickly ran into problems with date formatting.

I have a dataset containing transaction with three types of dates: BUSDATE, SPOTDATE, MATURITY. Each transaction is represented on two lines, and I want BUSDATE and SPOTDATE from line 1 but MATURITY from line 2.

In the original set, the dates are in YYYY-MM-DD format.

DATA masterdata;
SET sourcedata(rename(BUSDATE=BUSDATE2 SPOTDATE=SPOTDATE2 MATURITY=MATURITY2));

BUSDATE=BUSDATE2;
SPOTDATE=SPOTDATE2;

IF TRANS_TYPE='Swap' THEN;
MATURITY=SPOTDATE;

RUN;

Problem is, this returns something like 17169 (which I guess is the number of days from a certain date).

How can I make it output in YYYY-MM-DD format - or is this approach wrong; should I first convert the date variables to some SAS date format?

like image 994
beerskij Avatar asked Dec 02 '22 23:12

beerskij


1 Answers

if you have valid SAS dates, just add a FORMAT statement to your DATA STEP.

Format busdate spotdate maturity yymmdd10. ;

SAS dates are numeric variables. They represent the number of days since 1/1/1960. You use a FORMAT to display dates.

like image 132
Jay Corbett Avatar answered Dec 22 '22 23:12

Jay Corbett