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-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 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
  • 567 views
  • 0 likes
  • 2 in conversation