Solved

how to add to sas date

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…

732 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