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
- /
- Decoding sas code

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-21-2014 10:33 AM

I have been asked to help convert some code from sas to another software application

code sample 1

months_in_trial = **max(1,min(5,1+**intck('month',trial_start_dt,&pbd_date)));

I understand a portion of the code intck('month',trial_start_dt,&pbd_date))); means to take trial_start_dt and compare it to the &pbd_date. I am attempting to decode the portion marked in red.

code sample 2:

trial_start_dt = intnx( 'month' ,d_lm_trial_on_street_dt

**,1+(day(d_lm_trial_on_street_dt)>15) );**

It appears the code is saying to compare the trial_start_dt with the first day of the tria_on_the_street_dt then add 15 days. I am looking for confirmation.

Accepted Solutions

Solution

07-21-2014
10:48 AM

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

Posted in reply to Q1983

07-21-2014 10:48 AM

You might have to study up on a couple of things ... how does SAS store dates, what do the functions INTCK and INTNX actually do ...

Since Tom already commented on the second code sample, here's the idea of the first one.

INTCK computes number of months that have passed. (Technically, it calculates how many "1st of the month" dates fall between the two dates.) The Min/Max computations are more often found in SQL code for bounding a variable. This code is basically saying to calculate how many months have passed, then add 1, then limit the calculation to falling between 1 and 5. If the calculation comes up with more than 5, use 5. If it comes up with less than 1, use 1.

Good luck.

All Replies

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

Posted in reply to Q1983

07-21-2014 10:42 AM

Result of boolean expressions in SAS will be 0 or 1.

Do (day(xxx)>15) will return 1 if the day of the month is greater than 15 and 0 otherwise.

So it the INTNX function will generate the next month when the day of the month is the 15th or earlier and the month after that when the day of the month is after the 15th.

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

07-21-2014 10:55 AM

Thanks

Solution

07-21-2014
10:48 AM

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

Posted in reply to Q1983

07-21-2014 10:48 AM

You might have to study up on a couple of things ... how does SAS store dates, what do the functions INTCK and INTNX actually do ...

Since Tom already commented on the second code sample, here's the idea of the first one.

INTCK computes number of months that have passed. (Technically, it calculates how many "1st of the month" dates fall between the two dates.) The Min/Max computations are more often found in SQL code for bounding a variable. This code is basically saying to calculate how many months have passed, then add 1, then limit the calculation to falling between 1 and 5. If the calculation comes up with more than 5, use 5. If it comes up with less than 1, use 1.

Good luck.