BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
IgawaKei29
Quartz | Level 8

So I have two sets of dates one is Start_Date the other Closed_Date.  Start_Date is always populated, however Closed_Date can be null.  I have a formula in Excel that does the job, but I wanted to migrate this into SAS.

 

Excel Formula: =IF(I5="", TODAY() - H5,I5-H5)

 

So what I am trying to do is if Closed_Date is null then take today's date and subtract the Start_Date which will give me days open.  However if the Closed_Date has a value, subtract that value from the Start_Date to give me days open.

 

How would I transform this excel code into SAS code?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Something like this in a DATA step should work:

 

if closed_date > . then days_open = closed_date - start_date;

else days _open = today() - start_date;

 

There are minor efficiency considerations that could avoid calling the TODAY() function so many times.  But that would be way down the list of priorities.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Something like this in a DATA step should work:

 

if closed_date > . then days_open = closed_date - start_date;

else days _open = today() - start_date;

 

There are minor efficiency considerations that could avoid calling the TODAY() function so many times.  But that would be way down the list of priorities.

IgawaKei29
Quartz | Level 8

Thank you this is perfect.  I had to play around with the dates a little, but once I did the count worked perfectly.

 

 

data work.test;
 set work.extract;
  format closed_date start_date date9.;
 
   closed_date=datepart(closed_date);
   start_date=datepart(start_date);


    if closed_date > . then days_open = closed_date - start_date;
    else days_open = today() - start_date;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 747 views
  • 1 like
  • 2 in conversation