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
- /
- SAS Procedures
- /
- help with if

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-07-2015 05:19 PM

` data birth; input name $ bday :mmddyy10.; datalines; Miguel 12/31/1973 Joe 02/28/1976 Rutger 03/29/1976 Broguen 03/01/1976 Susan 12/12/1976 Michael 02/14/1971 LeCe 11/09/1967 Hans 07/02/1955 Lou 07/30/1960 ; `

`data ages;`

set birth;

retain current;

if _n_=1 then current=today();

format bday current worddate20.;

age=int(intck('month',bday,current)/12);

if month(bday)=month(current) then age=age-(day(bday)>day(current));

run;

proc print;

run;

How is the if condition solved here?Can someone explain it?Thanks.

Accepted Solutions

Solution

07-07-2015
06:04 PM

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

Posted in reply to NoorulIyn

07-07-2015 06:04 PM

That is comparison that returns true/false or 1/0. So if day(bday)>day(current) is true it becomes 1 and the equation becomes:

age=age-1;

otherwise it becomes:

age=age-0;

You can test it via

Y=day(bday)>day(current);

There's some details and comparisons on these formula's here:

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

I think intck with age option also calculates age correctly as of SAS 9.3+

All Replies

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

Posted in reply to NoorulIyn

07-07-2015 05:23 PM

Which if condition?

The first states uses the automatic variable _n_, which essentially states if this is the first record in the dataset set the variable current to today.

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

Posted in reply to NoorulIyn

07-07-2015 05:44 PM

Sorry for not being clear,the second if.(**day(bday)>day(current)**

Solution

07-07-2015
06:04 PM

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

Posted in reply to NoorulIyn

07-07-2015 06:04 PM

That is comparison that returns true/false or 1/0. So if day(bday)>day(current) is true it becomes 1 and the equation becomes:

age=age-1;

otherwise it becomes:

age=age-0;

You can test it via

Y=day(bday)>day(current);

There's some details and comparisons on these formula's here:

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

I think intck with age option also calculates age correctly as of SAS 9.3+

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

Posted in reply to NoorulIyn

07-08-2015 01:03 AM

SAS evaluates the expression in an IF-THEN statement to produce a result that is either True or False (1 or 0). A result of zero causes the expression to be false, while a nonzero result causes the expression to be true.

Back to your question,

The MONTH function returns a numeric value that represents the month from a SAS date value. Numeric values can range from 1 (Jan.) through 12 (Dec.).

If month(bday)=month(current) means if the month of variable ‘bday’ is equal to current month.