AFHood Group Blog The thoughtless yammerings of marketing junkies..

3Dec/090

SAS INTNX function ( add days, months, years, etc )

The INTNX function increments dates, times, or datetimes by specific or custom intervals.

Here is the basic syntax for INTNX:

INTNX(interval[multiple.shift-index], start, increment[, alignment])

The interval can be a set value like - DAY, WEEK, DTWEEK, YEAR, etc. You can also specify a custom interval. We will post more on that later.

The multiple is optional and used as such. If you want the interval to be a 2 year period or biennial, you could use YEAR2. It is the same with weeks. If you were calculating 2 week pay periods and you wanted to increment by such, you would declare the interval to be WEEK2.

The shift-index lets you define a starting point within the interval. An example would be to start the week on Monday.  The interval designation should be WEEK1.2 .

The start is your date, time, or datetime at which you want to begin the increment.

Increment is a positive or negative integer representing the number of interval shifts that should be made from the start.

Alignment is an excellent tool. It allows you to designate at which point SAS should return within an interval. You can specify:

B - beginning

M - middle

E - end

S - same

The default for alignment is beginning.

11Oct/090

Detecting the end of a SAS data set ( end= )

The END= option can help you determine when you have reached the last record in your dataset. Here is a syntax example:

data new_ds;

set old_ds end=end_var;

if end_var=1 then text='This is the last variable';

run;

The end= option creates a temporary variable, in the example it is end_var. This variable is not written to the output dataset. The variable is numeric and has a value of 1 to specify the last record.

Do not use this option with the point option.

This option is helpful when you only want to output the last record (good for summing data).

data new_ds (drop=transactional_record);

set old_ds end=last_record;

sum_var+transactional_record;

if last_record=1;

run;

18Sep/091

Using SELECT groups for conditional processing

What are Select Groups?

Select Groups are another way SAS enables conditional processing of datasets.

When should we use Select Groups instead of if-then statements?

According to our friends at SAS, you should utilize Select Groups when your conditional criteria is mutually exclusive and numeric. When this is the case, Select Groups are more efficient than if-then processing.

Here are a few examples of conditional processing using Select Groups:

data NEW_DS;

set DS1;

select var1;

when (1) var2='YES';

when (2) var2='NO';

otherwise var2='UNKNOWN';

end;

run;

data NEW_DS;

set DS1;

select;

when (var1=1 and var2='JAN') var3='YES';

when (var1=2 and var2='FEB') var3='NO';

otherwise var3='UNKNOWN';

end;

run;