BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Tom
Super User Tom
Super User

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.

Q1983
Lapis Lazuli | Level 10

Thanks

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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