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

Indulge for a moment in the charming fantasy that you have a table with two columns, called DealStartDate and DealEndDate. Both are in the DATE9 format, displayed as for example 29AUG2012 and 02SEP2012. A mysterious stranger asks you to create a new column called DealLifetime, which should display how long the deal lasted (basically DealEndDate-DealStartDate).

How would you choose to display DealLifetime? As a simple numeric variable displaying the number of days? Is there a practical way to display the years, months, days, etc., in a single field? The format should be intuitive.

Thanks for your time. Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hi,

Hope this is what you are expecting, just separated the day, month and year. please let me know if this is not what you are looking for..

data test;

    input date1 : date9. date2 :date9.;

    format date1 date2 date9.;

    days_month_year=catx('-',put(intck('day',date1,date2),8.),put(intck('month',date1,date2),8.),put(intck('year',date1,date2),8.));

  

cards;

29AUG2012 02SEP2012

;

run;

                                                                                            days_

                                                                                            month_

                                            Obs        date1         date2           year

                                             1     29AUG2012    02SEP2012    4-1-0

Thanks,

Jagadish

Thanks,
Jag

View solution in original post

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

Hi,

Hope this is what you are expecting, just separated the day, month and year. please let me know if this is not what you are looking for..

data test;

    input date1 : date9. date2 :date9.;

    format date1 date2 date9.;

    days_month_year=catx('-',put(intck('day',date1,date2),8.),put(intck('month',date1,date2),8.),put(intck('year',date1,date2),8.));

  

cards;

29AUG2012 02SEP2012

;

run;

                                                                                            days_

                                                                                            month_

                                            Obs        date1         date2           year

                                             1     29AUG2012    02SEP2012    4-1-0

Thanks,

Jagadish

Thanks,
Jag

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 682 views
  • 0 likes
  • 2 in conversation