Solved

how to add to sas date

Posted on 2011-02-18
5
1,031 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 66
SQL anywhere 11 databases 1 82
ODBC Question 3 42
T-SQL: Do I need CLUSTERED here? 13 45
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

822 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