Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date difference and convert to the number of days elapsed

Status
Not open for further replies.

sap1958

Technical User
Oct 22, 2009
138
US
%LET ElapseTime = ProjEndDate-ProjStDate;

data combine1;
set combine;
TotalProjDays1=&ElapseTime;
AmtSpentPercentage=&PercentSpent;
run;

For the elapse time I do get the difference between the ProjStDate and ProjEndDate however the number is very large. Here is a sample output (shown horizontally

ProjID
1
ProjStDate
15NOV2008:00:00:00
ProjEndDate
15DEC2009:00:00:00
TotalProjDays
34128000

How can I convert the TotalProjDays to obtain the true # of days (in this case from 11/5/08 to 12/5/09??


 
Hey,

I think the problem is that your projstdate and projenddate are in a datetime format not a date format. You need to take the datepart of these and then do your difference. I'm not sure if you can do it in a %let statement just by putting datepart(projectstdate)-datepart(projectstdate) or if you need to correct the formats before you use them in %let.

Does that help?
 
Beccy,

I think in this case the OP is asking for the correct amount of days in true numbers rather than a SAS number.

Having said that Sap, beccy is right that using datepart would make the calculation less error prone.

I'd also suggest in your macro'd calculation to 'sum' it.

Eg =sum( ProjEndDate-ProjStDate);

This will stop SAS erroring on blank values.

There are many ways to work out the true number of days and without knowing your SAS version i will show you the INTCK way as I know it will work on most older versions to.

So it will be something like this:

days=intck(‘days’,sdate,edate);

Where sdate is your start date var and edate is your end date var.

Id imagine you'd use something like this:

%LET ElapseTime = intck('days',ProjStDate,ProjEndDate);

data combine1;
set combine;
TotalProjDays1=&ElapseTime;
AmtSpentPercentage=&PercentSpent;
run;

HTH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top