<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to format date in fortnightly interval with a user defined starting dat in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30615#M7275</link>
    <description>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.&lt;BR /&gt;
 &lt;BR /&gt;
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&lt;BR /&gt;
 &lt;BR /&gt;
You may still need to use the INTNX function to create the user-defined format. &lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start&lt;BR /&gt;
Alan    1 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                             &lt;BR /&gt;
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?&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start&lt;BR /&gt;
Alan   15 Jan 2009&lt;BR /&gt;
Bob    19 Jan 2009&lt;BR /&gt;
Carl    24 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                              &lt;BR /&gt;
Or, do you want the original dataset variables, plus a new variable:  &lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start            Next&lt;BR /&gt;
Alan    1 Jan 2009     15 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009     19 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009     24 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                &lt;BR /&gt;
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????&lt;BR /&gt;
 &lt;BR /&gt;
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. &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name    P_Date        Start_Period&lt;BR /&gt;
Alan    1 Jan 2009     1 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009     1 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009     1 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
Your verbal description of how the date needs to be adjusted is certainly do-able in a couple of different ways. &lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
 &lt;BR /&gt;
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.&lt;BR /&gt;
 &lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Here's another possible scenario: You need to generate a file with all the 2 week or fortnightly periods in 2009:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs     firstday      lastday&lt;BR /&gt;
&lt;BR /&gt;
  1    01JAN2009    14JAN2009&lt;BR /&gt;
  2    15JAN2009    28JAN2009&lt;BR /&gt;
  3    29JAN2009    11FEB2009&lt;BR /&gt;
  4    12FEB2009    25FEB2009&lt;BR /&gt;
  5    26FEB2009    11MAR2009&lt;BR /&gt;
  6    12MAR2009    25MAR2009&lt;BR /&gt;
  . . . more . . .&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                     &lt;BR /&gt;
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:&lt;BR /&gt;
date + 13 = end of period&lt;BR /&gt;
date + 14 = start of next period&lt;BR /&gt;
               &lt;BR /&gt;
cynthia</description>
    <pubDate>Tue, 15 Dec 2009 15:23:17 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-12-15T15:23:17Z</dc:date>
    <item>
      <title>How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30612#M7272</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
How to format date in fortnightly interval with a user defined starting date (e.g. 1 Jan 2009), similar to the format listed below?&lt;BR /&gt;
 &lt;BR /&gt;
SAS Date Annual YEAR4. 1991 &lt;BR /&gt;
               Quarterly YYQC6. 1991:4 &lt;BR /&gt;
               Monthly MONYY7. OCT1991 &lt;BR /&gt;
               Weekly WEEKDATX23. Thursday, 17 Oct 1991</description>
      <pubDate>Tue, 15 Dec 2009 03:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30612#M7272</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-15T03:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30613#M7273</link>
      <description>Hi:&lt;BR /&gt;
  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?&lt;BR /&gt;
&lt;BR /&gt;
  If you need to advance the date by -exactly- 14 days and your starting date is a SAS date variable, then you could either use the INTNX function or you could simply add 14 to the starting date. The advantage of the INTNX function is that you can advance a date by a certain interval and pick the beginning of the fortnight week, the middle of the fortnight week or the end of the fortnight week or the same date to end the fortnight on. Described here in the doc and papers:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000212700.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000212700.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi31/027-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/027-31.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/forum2007/226-2007.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2007/226-2007.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 15 Dec 2009 05:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30613#M7273</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-12-15T05:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30614#M7274</link>
      <description>Hi Cynthia&lt;BR /&gt;
&lt;BR /&gt;
Many thanks for your reply.&lt;BR /&gt;
&lt;BR /&gt;
I have a SAS date variable (range from 1 Jan 2009 to 31 Dec 2009). I want to recode this date variable to a new fixed fortnightly period variable. &lt;BR /&gt;
&lt;BR /&gt;
The first period is from 1Jan2009 to 14 Jan 2009 and 1 Jan 2009 is the value for the first period. Then incremented by 14 days, the first date of the period is the value for the period.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
Paris</description>
      <pubDate>Tue, 15 Dec 2009 06:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30614#M7274</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-15T06:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30615#M7275</link>
      <description>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.&lt;BR /&gt;
 &lt;BR /&gt;
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&lt;BR /&gt;
 &lt;BR /&gt;
You may still need to use the INTNX function to create the user-defined format. &lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start&lt;BR /&gt;
Alan    1 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                             &lt;BR /&gt;
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?&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start&lt;BR /&gt;
Alan   15 Jan 2009&lt;BR /&gt;
Bob    19 Jan 2009&lt;BR /&gt;
Carl    24 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                              &lt;BR /&gt;
Or, do you want the original dataset variables, plus a new variable:  &lt;BR /&gt;
[pre]&lt;BR /&gt;
Name   Start            Next&lt;BR /&gt;
Alan    1 Jan 2009     15 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009     19 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009     24 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                &lt;BR /&gt;
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????&lt;BR /&gt;
 &lt;BR /&gt;
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. &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name    P_Date        Start_Period&lt;BR /&gt;
Alan    1 Jan 2009     1 Jan 2009&lt;BR /&gt;
Bob     5 Jan 2009     1 Jan 2009&lt;BR /&gt;
Carl   10 Jan 2009     1 Jan 2009&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
Your verbal description of how the date needs to be adjusted is certainly do-able in a couple of different ways. &lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
 &lt;BR /&gt;
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.&lt;BR /&gt;
 &lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Here's another possible scenario: You need to generate a file with all the 2 week or fortnightly periods in 2009:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs     firstday      lastday&lt;BR /&gt;
&lt;BR /&gt;
  1    01JAN2009    14JAN2009&lt;BR /&gt;
  2    15JAN2009    28JAN2009&lt;BR /&gt;
  3    29JAN2009    11FEB2009&lt;BR /&gt;
  4    12FEB2009    25FEB2009&lt;BR /&gt;
  5    26FEB2009    11MAR2009&lt;BR /&gt;
  6    12MAR2009    25MAR2009&lt;BR /&gt;
  . . . more . . .&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                     &lt;BR /&gt;
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:&lt;BR /&gt;
date + 13 = end of period&lt;BR /&gt;
date + 14 = start of next period&lt;BR /&gt;
               &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 15 Dec 2009 15:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30615#M7275</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-12-15T15:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30616#M7276</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
data dates;&lt;BR /&gt;
do dt=mdy(1,3,2009) to mdy(2,28,2009);&lt;BR /&gt;
  output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set dates;&lt;BR /&gt;
do x=mdy(1,1,2009) to mdy(1,1,2010) by 14;&lt;BR /&gt;
  if dt lt x then do;&lt;BR /&gt;
    fortnight_dt = x-14;&lt;BR /&gt;
	leave;&lt;BR /&gt;
  end;&lt;BR /&gt;
end;&lt;BR /&gt;
putlog dt= fortnight_dt= ;&lt;BR /&gt;
format dt fortnight_dt x date9.;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 15 Dec 2009 16:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30616#M7276</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-15T16:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to format date in fortnightly interval with a user defined starting dat</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30617#M7277</link>
      <description>Thank you both for your very helpful information.&lt;BR /&gt;
I have solved the problem using 'intnx'.&lt;BR /&gt;
&lt;BR /&gt;
Paris</description>
      <pubDate>Wed, 16 Dec 2009 01:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-format-date-in-fortnightly-interval-with-a-user-defined/m-p/30617#M7277</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-16T01:46:52Z</dc:date>
    </item>
  </channel>
</rss>

