BookmarkSubscribeRSS Feed
Vortex
Calcite | Level 5

Hi I am looking for a code that does the feature by JP in this thread. The issue is that if the year of the start and end date is different it does not work.

Example, Dec 2, 2014 and ends January 3, 2015.

Thank you

7 REPLIES 7
Steelers_In_DC
Barite | Level 11

Based on your question I'm not sure what you are asking for.  Is this what you want?

data have;

format date1 date2 mmddyy10.;

date1 = '02DEC2014'd;

date2 = '03JAN2015'd;

run;

data want;

set have;

date_diff = intck('day',date1,date2);

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As they are date variables, you don't actually need to use a function:

data want;

set have;

date_diff = date2 - date1;

run;

Vortex
Calcite | Level 5

Sorry the link didn't show up:

https://communities.sas.com/thread/51733

I am trying to find another code that does similar to this. The issue with this it does not work for cross year boundaries i.e December 2014 and January 2015

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post some test data.  I personally would expand your data for each date  then sum it up, note to transpose you would need to know year and month e.g.

data have;

  effective_date="01JAN2014"d;

  end_date="14FEB2015"d;

  output;

run;

data inter;

  set have;

  do day_date=effective_date to end_date;

    mnth=month(day_date);

    yr=year(day_date);

    output;

  end;

run;

proc sql;

  create table WANT as

  select  MNTH,

          YR,

          COUNT(1) as CNT

  from    INTER

  group by YR,

            MNTH;

quit;

Vortex
Calcite | Level 5

Here are some sample data:

Visit Number     Checkin Date  CheckoutDate

234212/25/20141/6/2015
123412/27/20141/1/2015

Should be this:

Visit Number     Checkin Date  CheckoutDate   Dec 2014    Jan 2015

234212/25/20141/6/201576
123412/27/20141/1/201551
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, my program should work on that.  I wouldn't go with having dates as columns though.  Its a bad idea in the longer term, I mean if you had a time period (not necessarily on one row, but over all data) of several years, you can end up with lots of columns with few data in.  Better to keep it normalised as my output will do, or genericise the columns, e.g. COL1-COLx, so you can use arrays and fill up only the ones you need.

Vortex
Calcite | Level 5

Hey RW9, I just tried and yes I can use it!

Thank you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1772 views
  • 4 likes
  • 3 in conversation