BookmarkSubscribeRSS Feed
Sujithpeta
Quartz | Level 8

Hey guys;

 

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.

 

Thanks!

9 REPLIES 9
Astounding
PROC Star

If you have two dates, you don't need INTCK:

 

Day_Death = Death_DT - Index;

Sujithpeta
Quartz | Level 8

I tried it, but I'm ending up getting a date format output instead of numeric days.

Astounding
PROC Star

Not possible.  Give one example of the inputs and outputs that you believe to be incorrect.

ballardw
Super User

@Astounding wrote:

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.

 

The

Data M.Master;

   set M.Master;

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.

 

Sujithpeta
Quartz | Level 8
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;

Output:

Capture.PNG

Astounding
PROC Star

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.

ballardw
Super User

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.

Sujithpeta
Quartz | Level 8

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.

ballardw
Super User

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.;

run;

for example.

I believe from what you have shown that at least one of your variables does not actually have the SAS format you

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1360 views
  • 0 likes
  • 3 in conversation