Solved

how to add to sas date

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL 11 80
Compare and update data between two databases 6 58
Oracle function works in 11g but not in 12c 21 71
Fixing Non-Standard characters in text 8 91
Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Read about achieving the basic levels of HRIS security in the workplace.
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…

910 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

18 Experts available now in Live!

Get 1:1 Help Now