Help using Base SAS procedures

Reg:Dates

Reply
Regular Contributor
Posts: 229

Reg:Dates

Hi
i have a date1 variable in this the observations was 05/01/07 and now i want to create another variable date2 and the observations shd be 05/02/07 up to end of that year as i have tried to add days to the first observation but the days diff from one month to anoher.

Here is the output:

date1 date2 date3 date4 ....... date12
05/01/07 05/02/07 05/03/07 05/04/07 .......................... 05/12/07 Message was edited by: Main
Super Contributor
Super Contributor
Posts: 3,174

Re: Reg:Dates

A SAS DATA step to increment your source variable by 1 while assigning a new DATE2 variable. A DO loop within the DATA step will provide logic to both assign the new variable and issue an OUTPUT with each loop iteration.

The SAS support http://support.sas.com/ website has SAS-hosted documentation and supplemental technical topic papers for reference. I used the SEARCH facility at the site and found several references - some pasted below.

Scott Barry
SBBWorks, Inc.

Looking for a Date? A Tutorial on Using SAS® Dates and Times
Arthur L. Carpenter, California Occidental Consultants
http://www2.sas.com/proceedings/sugi30/255-30.pdf

Working with Dates in the SAS System
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm
Super Contributor
Posts: 474

Re: Reg:Dates

To increment a date value use the INTNX function.

See: http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000212700.htm

Greetings from Portugal.

Daniel Santos at www.cgd.pt
Super Contributor
Super Contributor
Posts: 3,174

Re: Reg:Dates

Posted in reply to DanielSantos
For consideration, using INTNX may be useful if incrementing a DATETIME variable by the date-portion, however having a DATE variable and incrementing sequentially (adding 1 increments to the next date) really does not require using INTNX.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: Reg:Dates

Scott is right, to add 1 day, you just need to increment the DATE variable by 1.

But, I think Main is having trouble to advance one month (quote: "...but the day diff from one month to anoher"), so in this case, INTNX would be the most simple way of doing it.

Cheers from Portugal.

Daniel Santos at www.cgd.pt
Super Contributor
Super Contributor
Posts: 3,174

Re: Reg:Dates

Posted in reply to DanielSantos
My mistake in not reading the post accurately. You make an excellent choice with using INTNX, Daniel.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 5 replies
  • 127 views
  • 0 likes
  • 3 in conversation