Solved

how to add to sas date

Posted on 2011-02-18
5
1,028 Views
Last Modified: 2013-11-16
Trying to add a value to a sas date in a sql query
0
Comment
Question by:eelaprade
  • 3
5 Comments
 
LVL 14

Expert Comment

by:Aloysius Low
ID: 34925919
if you are looking to doing something simple like adding or reducing the number of days, just perform it like a normal numerical addition or subtraction

otherwise, there's the INTNX function you can make use of

what exactly are you trying to do?
0
 

Author Comment

by:eelaprade
ID: 34926018
Hi-
I am using the SAS v8
I want to know if I can use poc SQL for date additions i.e. I want to add 365 days to a start date and creat a enddate.  Can I use the normal formart MMDDYYYY + 365 and get the last date as MMDDYYYY?
How would a program for this look like?

Please advise
Thanks

0
 
LVL 14

Expert Comment

by:Aloysius Low
ID: 34926129
it doesn't matter what the format of the date is as long as the value you are trying to add is a date field.

e.g.
data work.test_date;
  format date_value end_date date9.;
  date_value = '01jan2011'd;
  end_date = date_value + 365;
run;
0
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 200 total points
ID: 34926148
forgot to add the proc sql part:

proc sql;
  create table new_date as
    select *, (date_value + 365) as end_date_sql format date9.
    from test_date;
quit;

you'll see that in new_date table, end_date_sql and end_date has the same value :)
0
 
LVL 7

Assisted Solution

by:d507201
d507201 earned 300 total points
ID: 34927240
SAS dates are stored as numbers--the number of days before or after January 1, 1960.  So you can add and subtract numbers of days from them.  If you're going to be working a lot with dates then you should learn to use the INTNX function that Iowaloysius suggests and the INTCK function because they are much more powerful than just adding and subtracting days.  Also, there are some great SAS Conference papers about date handling.  Go to http://www.lexjansen.com/sugi/ and search for 'date handling'.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now