Do you mean that you have a user-defined starting date and you want to advance the date by 14 days (a fortnight)? Or that you want to advance the date to some particular day in the 2-week period? Do you want to do this one time? or once for every observation or generate dates 2 weeks apart for a fixed period of time or fixed number of intervals?
Generally, to recode means to use a user-defined format. This means that the date would still be internally stored as 1 Jan 2009 (for example) but would be -displayed- on reports as 14 Jan 2009. Is this what you want? If so, then investigate user-defined formats and how to create them from a SAS dataset using the CNTLIN option.
On the other hand, if by "recode" you mean to create a new variable, then you probably don't need a user-defined format and can just use the INTNX function in a DATA step program to create your new variable
You may still need to use the INTNX function to create the user-defined format.
I'm also not sure what you mean by "the first date of the period is the value for the period" -- consider this dataset of 2 variables or columns:
Alan 1 Jan 2009
Bob 5 Jan 2009
Carl 10 Jan 2009
Do you want a NEW dataset that is a copy of the old dataset, but with the START variable -changed- so it represents the start day of the -next- period?
Alan 15 Jan 2009
Bob 19 Jan 2009
Carl 24 Jan 2009
Or, do you want the original dataset variables, plus a new variable:
Name Start Next
Alan 1 Jan 2009 15 Jan 2009
Bob 5 Jan 2009 19 Jan 2009
Carl 10 Jan 2009 24 Jan 2009
Or, do you just want the original dataset to -display- the start value when you use the dataset with PROC PRINT or some other report procedure????
Another way to interpret your sentence is that if someone's date falls -within- the 2 week period, then you want their START variable to be adjusted to be the first day of the 2 week period.
Name P_Date Start_Period
Alan 1 Jan 2009 1 Jan 2009
Bob 5 Jan 2009 1 Jan 2009
Carl 10 Jan 2009 1 Jan 2009
Your verbal description of how the date needs to be adjusted is certainly do-able in a couple of different ways.
However, your input data structure and your desired output (either data or report) will determine the method you use in a SAS program -- whether you use a DATA step program and the INTNX function; whether you use a DATA step program to make a user-defined format; what the output dataset looks like; or what the output report looks like.
Here's a possible scenario: You have data with customers and purchase dates. You want to summarize the amounts they spent by each 2-week (fortnightly) period. So the calculated or adjusted date needs to be used for summary and reporting purposes.
Here's another possible scenario: You have data with patients and their doctor's visits and you want some counts of how many patients' visits fell within each 2 week period.
Here's another possible scenario: You have data with customer name or patient name and some date. You need to track or check something on a date basis. So if your customer's date is 1 Jan 2009, you need to check something based on 15 Jan 2009 being the start of the period after 1 Jan 2009.
Here's another possible scenario: You need to generate a file with all the 2 week or fortnightly periods in 2009:
Obs firstday lastday
Having some idea of what the input data looks like and what you need to do (the big picture), will help provide the context for the kind of program you need to write. You've provided one piece of the puzzle:
date + 13 = end of period
date + 14 = start of next period
I agree with the approach of using a user-defined SAS format with value range (START to END) and a SAS numeric date value as the LABEL (returned as character and convert back to a SAS internal DATE variable number.
Here is a code piece to illustrate how you could use DO/END logic with a BY interval to generate the START and END values for a PROC FORMAT CNTLIN= technique. The first DATA step generates some date values for data-points to test, and the second DATA step is simply limiting the check to a pre-defined date range.
do dt=mdy(1,3,2009) to mdy(2,28,2009);
do x=mdy(1,1,2009) to mdy(1,1,2010) by 14;
if dt lt x then do;
fortnight_dt = x-14;
putlog dt= fortnight_dt= ;
format dt fortnight_dt x date9.;