user1481397
user1481397

Reputation: 433

SAS date variable

I have a SAS data set A and one of the column is date. 31AUG2010. when I do the following code:

data b;
set a;
newdate=date;
run;

The newdate becomes numeric and 31AUG2010 becomes 18505. How do I solve it?

Upvotes: 0

Views: 55

Answers (3)

momo1644
momo1644

Reputation: 1804

You have to assign a date format to the new field. Since Date is a numeric field in SAS; SAS assigns the default format which is numeric.

You can assign the format by adding a format statement

data test;
format newdate date9.;
date='31AUG2010'd;
newdate=date;
run;

date has no format assigned but newdate has date9. format assigned.

Output:

newdate=31AUG2010 date=18505

Upvotes: 0

DomPazz
DomPazz

Reputation: 12465

Dates are just the number of days from 01JAN1960. You need to apply a format. A format doesn't change how the number is stored, just how it is presented to you.

Data a;
set a;
format newdate date9.;
newdate=date;
run;

Upvotes: 0

Reeza
Reeza

Reputation: 21294

Apply a format. See the example below with two different formats applied.

data b;
set a;
newdate=date;
newdate2 = date;

format newdate date9. newdate2 ddmmyy10.;
run;

Upvotes: 1

Related Questions