01-10-2018 04:34 PM - edited 01-10-2018 04:39 PM
I'm trying to get days difference between two dates in the format YYMMDDN8.
data M.Master; set M.Master; by DESY_SORT_KEY; Day_Death = intck('dtday', Index, DEATH_DT); run;
Every row has same days, Can you guys help me out.
01-10-2018 05:14 PM
Not possible. Give one example of the inputs and outputs that you believe to be incorrect.
Perhaps the data set already has a variable Day_Death with a date format from a previous trial of this code exercise.
coding could well have added lots of things in prior runs such as FORMAT for Day_death.
Also use of 'dtday' also implies that you should have DATETIME variables, not Dates. So try 'day' instead or the subtraction.
You may want to go back and rebuild the M.Master set to before you attempted to add this variable the first time.
01-10-2018 05:19 PM
data M.Master; set M.Master; by DESY_SORT_KEY; format DEATH_DT YYMMDDN8.; format Index YYMMDDN8.; if DEATH_DT NE "" then Death = 1; Day_Death = (DEATH_DT - Index); run;
01-10-2018 05:26 PM
Looking at these results, I would guess @ballardw hit the nail on the head. Your existing data set already contains a variable named DAY_Death, and it already has a date format. One easy way to get rid of that would be on the SET statement:
set M.Master (drop=Day_Death);
That assumes you have inspected the data and agree that you want to get rid of it.
01-10-2018 08:02 PM
It would also be interesting to see what the actual assigned format for the DAY_death variable is. In a value like 20101717 while 2010 might be a year the 1717 is not a valid month and day combination in any form, there is no month 17 in SAS dates.
And without a shown value for INDEX I'm at loss for what is happening.
01-11-2018 09:50 AM
Day_Death is created to calculate the days difference between days and don't exist before.
Index date originally was in the format YYMMDDN8. and DEATH_DT was in the format BEST12.
01-11-2018 10:28 AM
The internal numeric representation of a date corresponding to your Death_dt of 20130420 (20APR2013) is 19468. To have a value of
death_dt - index = 20111309 as shown above then Index would have to have a value of -20091841 which has a value prior to the earliest valid SAS date values (by about 19700000 days). HOWEVER that value of Index would correspond to a datetime of 13MAY59:10:55:59.
If index is supposed to be 20120428 (28APR2012) then your value of Death_dt is 20130420 and is not a SAS date variable at all.
So what is the actual value of your Index variable? and if the SAS format assigned is actually YYMMDDN8. then show the unformatted values for Death_dt and Index for a few records.
Proc print data=have;
var death_dt index;
format death_dt index best12.;
I believe from what you have shown that at least one of your variables does not actually have the SAS format you