sas certification in pune Archives - DexLab Analytics | Big Data Hadoop SAS R Analytics Predictive Modeling & Excel VBA

## INTCK and INTNX: All about SAS Dates and Computing Intervals between Dates

The INTCK and INTNX functions in SAS helps you compute the time between events. This technical blog is based on the timeline of living US presidents, sourced from a Wikipedia table. The table data shows the number of years and days between events.

So, let’s start.

#### Gaps between dates

To calculate the interval between two dates, you can use these two SAS functions:

The INTCK function returns the number of time units between dates. The time unit can be selected in years, months, weeks, days, or whatever you feel like.

The INTNX function helps you compute the date that is 308 days away in the future from a specific date. This was just an example to help you understand what it means. The INTNX function returns a SAS date that is particular number of time units away from a particular date.

These two functions share a complimentary bond: where one calculates the difference between two dates, the other entitles you to add time units to a specified date value. Also, the INT part in both the functions denotes INTervals, and the terms INTCK and INTNX means Interval Check and Interval Next, respectively.

DexLab Analytics offers intensive SAS certification courses for candidates..

#### How to calculate anniversary dates

These two prime functions tend to be useful in counting the number of anniversaries between two dates along with calculating a future anniversary date. Use the ‘CONTINUOUS’ option for the INTCK function and the ‘SAME’ option for the INTNX function in the following manner:

The ‘CONTINUOUS’ option in the INTCK function helps you count the number of anniversaries of one date that occur before a second date. For example, the statement

`Years = intck('year', '30APR1789'd, '04MAR1797'd, 'continuous');`

returns the value 7 because there are 7 full years (anniversaries of 30APR) between those two dates. Without the ‘CONTINUOUS’ option, the function returns 8 as 01JAN occurs 8 times between those dates.

The statement

`Anniv = intnx('year', '30APR1789'd, 7, 'same');`

returns the 7th anniversary of the date 30APR1789. In some ways, it returns the date value for 30APR1796.

The most exciting part about these two functions is that they automatically handle leap years! Yes, you read that right. If you ask for the number of days within two dates, the INTCK function will show leap days in the result. If an event takes place on a leap day, and you ask the INTNX function to reveal the anniversary date, it will report 28FEB of the next year to the next anniversary date.

#### An algorithm calculating years and days between events

Go through the following algorithm to calculate the number of years and days between dates in SAS:

• Use the INTCK function with the ‘CONTINUOUS’ option to calculate the number of completed years between two dates
• Use the INTNX function to discover a third date, i.e. anniversary date, which is the same month and day like the start date, but takes place less than a year before the end date.
• Use the INTCK function to ascertain the number of days occurring between the anniversary date and the end date.

Here are the data steps that enable you to compute the time interval in years and days between the first few US presidential inaugurations and deaths.

```data YearDays; format Date prevDate anniv Date9.; input @1 Date anydtdte12. @13 Event \$26.; prevDate = lag(Date); if _N_=1 then do; /* when _N_=1, lag(Date)=. */ Years=.; Days=.; return; /* set years & days, go to next obs */ end; Years = intck('year', prevDate, Date, 'continuous'); /* num complete years */ Anniv = intnx('year', prevDate, Years, 'same'); /* most recent anniv */ Days = intck('day', anniv, Date); /* days since anniv */ datalines; Apr 30, 1789 Washington Inaug Mar 4, 1797 J Adams Inaug Dec 14, 1799 Washington Death Mar 4, 1801 Jefferson Inaug Mar 4, 1809 Madison Inaug Mar 4, 1817 Monroe Inaug Mar 4, 1825 JQ Adams Inaug Jul 4, 1826 Jefferson Death Jul 4, 1826 J Adams Death run;   proc print data=YearDays; var Event prevDate Date Anniv Years Days; run;```

In a nutshell, the INTCK and INTNX functions are consequential for calculating intervals between dates. In this blog, I discussed about two-less-popular options inn SAS, for more such SAS training related blogs, follow us at DexLab Analytics.

This post originally appeared onblogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html

#### Interested in a career in Data Analyst?

In the 2016 February report by Gartner, SAS bagged the top slot in its execution ability and was once again placed in the quadrant of leaders in the Magic Quadrant for Advanced Analytics Platforms.According to the description, as provided by Gartner, advanced analytics involves various sorts of data analysis through the use of quantitative methods of great sophistication like machine learning, statistics, simulation, data mining in its both predictive and descriptive forms as well as optimization.

The goal is come up with insights that are unlikely to be discovered through approaching business intelligence traditionally like query and reporting.

## Elementary Character Functions in SAS

Basically the number of functions present in the SAS program amount to three. They are Character Functions, Numeric Functions and Date and Time Functions. In this post we are going to take a brief look at Character functions of a basic nature.

### Suppose that there is this program with the following lines of command:

```Data Len_func ; input name \$ ; cards; Sandeep Baljeet
Neeta
.
;
run;
data Len_func; set Len_func ; Len=length(name);
Len_N=lengthn(name); Len_C=lengthc(name); run;
proc print; run;```

Here,

• The function called LENGTH returns the character value’s length.
• The function LENGTHN is more or less identical to the LENGTH function. The sole difference between the two lies in the fact that for a value missing character it returns the length that equals to 0 whereas LENGTH returns a value of 1.
• The function LENGTHC returns to the program the storage length of particular strings.

### Again let us consider the following lines of code:

```Data case ; input name \$ ;cards;
sandeep baljeet neeta
;
New_U=upcase(name); New_P=propcase(name);
run;
proc print; run;```

### Here the following functions are introduced:

• The function UPCASE converts all of the letters to the uppercase.
• The function PROPCASE serves to capitalize the first letter of all words and converts the remaining to lowercase.
• As might be guess from the convention conformed to while naming the function, LOWCASE transforms all letters to their lowercase counterparts.

### In the following program commands:

```Data AMOUNTS; input NAME \$20.; cards;
AA-RT-I
;
RUN;
Data AMOUNTS;
Set AMOUNTS; NAME1=COMPRESS(NAME,'-'); NAME2=COMPBL(NAME);
RUN;
PROC PRINT;
RUN;```

### Here we can see the following syntax:

1. Compress (Variable, ”want to remove”);
2. Compbl (Variable)
• The function COMPRESS removes blanks by default. It can also remove a particular specified character value as indicated by the code. In the example cited the character value ‘-‘is compressed.
• On the other hand the COMPBL function serves to result in a single blank from multiple ones.

For expert guidance, you will be well advised to enroll yourself in a SAS course from a reputed SAS Training institute. You may consider DexLab Analytics if you are in the vicinity of Delhi or noida.