1
votes

I need help with SAS datetime format. Dataset(including desired column exp_dt):

    datetime            valid           exp_dt
4OCT2017:13.00.00         1         5OCT2017:13.00.00   
4OCT2017:15.20.00         7         11OCT2017:15.20.00
6OCT2017:08.00.00         30        5NOV2017:08.00.00

So, I need to add valid values (number of days) to datetime. I've just started with SAS Base and I am not sure if any other datetime format is acceptable. I've tried with this, but not sure if even going in right direction:

PlannedSchedTime = datetime ;
Postunit = 'DAY' ;
postval = valid ;
exp_dt = put(intnx(Postunit,PlannedSchedTime,postval,'same'),datetime20.);
put exp_dt= ;
run;

Also, I'm working on project in SAS Enterprise Guide, so maybe there is easier way through the GUI tasks?

2

2 Answers

1
votes

You are definitely on the right path! Because you are dealing with datetime values, replace DAY by dtDAY.

If you don't want exp_dt to be a character column, don't use the put function but rather a format (e.g. format exp_dt2 datetime20.;).

1
votes

Here a code sample that will print your desired result. Like the other answer states, DTDAY will tell SAS to add days when the base value is a datetime instead of a date.

data datetimes;
    informat datetime anydtdtm. valid best12.;
    format datetime datetime20.;
    input datetime valid;
    cards;
4OCT2017:13.00.00 1
4OCT2017:15.20.00 7
6OCT2017:08.00.00 30
;
run;

data datetimes_added;
    set datetimes;
    format exp_dt datetime20.;
    exp_dt = intnx('DTDAY',datetime,valid,'SAME');
    put exp_dt = ;
run;