turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Base SAS

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-08-2015 07:33 AM

I would like to have the result of the following codes in year and days format.

years=9.1917808219 I want to see this as 9 year 191 days.

data dt;

a=today()-'01AUG2006'd;

b=a/365;

run;

Please help me.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KafeelBasha

10-08-2015 07:55 AM

I'm confused because 9.1917808219 is not 9 years 191 days.

It is 9 years and .1917808219 years (which is 70 days)

So please be more specific about what output you want.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KafeelBasha

10-08-2015 08:23 AM

I understand PaigeMiller here, its not clear what you want. From your given example you can reverse the formula you have given:

data dt; a=today()-'01AUG2006'd; b=a/365; c=b*365; d=c+"01AUG2006"d; format d date9.; run;

So b contains your 9.191... I fyou then multiply that by 365 and add the original base date back on you should arrive at today. However note that doing this whole a year is 365 days, rather than using proper interval functions is risky and might yield incorrect results. Why do you need to do this, have they not supplied the original dates used in the calculation as they should have.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KafeelBasha

10-08-2015 02:04 PM

That number (9.1917808219 I) must come from outside SAS as time intervals are not measured in years within SAS. Knowing where that time interval comes from would help finding a precise SAS equivalent.

PG

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

10-08-2015 02:53 PM - edited 10-08-2015 02:53 PM

If you execute the code shown in the original post, the number 9.1917808219 comes from the lines of code

```
a=today()-'01AUG2006'd;
b=a/365;
```

It's not clear to me what the user wants to do with this number, which (s)he misinterprets as 9 years 191 days

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KafeelBasha

10-08-2015 03:29 PM

Oh! I finally get it. You'll get exact numbers with SAS interval functions:

```
data dt;
years = intck("YEAR", '01AUG2006'd, today(), 'CONTINUOUS');
days = intck("DAY", intnx("YEAR", '01AUG2006'd, years, 'SAME'), today());
put (_ALL_) (=);
run;
```

PG