Help using Base SAS procedures

Decoding sas code

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

Decoding sas code

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
Super User
Posts: 5,081

Re: Decoding sas code

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.

View solution in original post


All Replies
Super User
Super User
Posts: 6,499

Re: Decoding sas code

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.

Frequent Contributor
Posts: 131

Re: Decoding sas code

Thanks

Solution
‎07-21-2014 10:48 AM
Super User
Posts: 5,081

Re: Decoding sas code

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 310 views
  • 0 likes
  • 3 in conversation