Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to add to sas date

Posted on 2011-02-18
5
Medium Priority
?
1,043 Views
Last Modified: 2013-11-16
Trying to add a value to a sas date in a sql query
0
Comment
Question by:eelaprade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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 1200 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
What we learned in Webroot's webinar on multi-vector protection.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

604 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