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?
-
it is already in date, SAS has only two data types char and num. Date is stored in num and format is used for display only. You can do all calculations on it– KiranFeb 26, 2019 at 15:03
1 Answer
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;
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;