Victor
Victor

Reputation: 17097

Convert number to SAS date with a DATE9 format

I have a SAS field where the datatype is number and format is date9. It has a value like 30SEP2018. How do I convert it to a SAS date so I can do date operations?

Upvotes: 0

Views: 1173

Answers (1)

Kiran
Kiran

Reputation: 3315

SAS dates are stored as number starting from 1/1/1960 and it starts form number = 0 and increases by 1 for every day. Your date is stored as number and then you get from proc contents and format is to display in the way you want.

 data have;
 input date:date9.;
format date date9.;
datalines;
30SEP2018
;

proc contents data=have;
run;

enter image description here

you can calculations on above date and gives you appropriate results as shown below

  data want;
   set have;
  new_date= date+1;
 new_date1= date-1;
 format new_date new_date1 date9.;
run;

proc print; run;

enter image description here

Upvotes: 2

Related Questions