Solved

PROC SQL: Delete rows in which two date fields differ by more than 250 days

Posted on 2009-05-18
6
750 Views
Last Modified: 2012-05-07
Hi all, I;m not familiar with PROC SQL (I think its similar to MS SQL)

I am running a statistics program called SAS and am trying to delete certain rows in a database. The fields 'Date_Announced' and 'Date' are the ones I am concerned with. I'm trying to subtract the two coloumns and then delete the rows for which the result is >250 . The sheet is called Asx.mergernew.

Can someone help me with the exact command to type into my command window?
0
Comment
Question by:hubfub
  • 4
  • 2
6 Comments
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409778
you can do something like:

delete from YourTableName where DATEDIFF(dd,Date_Announced,[date])>=205
0
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
ID: 24409789
if you want in stored procedure than use this one.




create proc DeleteRecord

as

begin

delete from YourTableName where DATEDIFF(dd,Date_Announced,[date])>=205

end
 
 

--run abov proc

exec deleteRecords

Open in new window

0
 
LVL 1

Author Comment

by:hubfub
ID: 24409805
HI RiteshShah

DATEDIFF is not a command that is recognised nor is it a field. Is there a way to get around this? One field in ours is Date and the other is Date_Announced. What is dd?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409811
DATEDIFF is a date function built in in SQL Server, "DD" gives you difference in days.

can't you even run below command?



select DATEDIFF(dd,getdate()-250,getdate())

Open in new window

0
 
LVL 1

Author Comment

by:hubfub
ID: 24409837
When I run that command it says 'syntax error'

I am trying to run these commands in a statistics program called SAS although the command window says PROC SQL - is this why the commands are not running?
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409985
those command should run in SQL Server, not familiar with PROC SQL.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

743 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

14 Experts available now in Live!

Get 1:1 Help Now