Help using Base SAS procedures

Converting 12OCT2012:00:00:00 to SAS numeric date

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Converting 12OCT2012:00:00:00 to SAS numeric date

Hi,

I'm trying to compare the dates in two fields, and delete the row based on a condition.  Here's what I have:

DATA PL.TREATMENT_PLANS_YEAR_365;

      SET PL.TREATMENT_PLANS_YEAR;

      current=date();

      date365=intnx('day',date(),365);

       if recalldate1>date365 then delete;

RUN;

recalldate 1 is in the format:

 

12OCT2012:00:00:00

date365 is in the SAS date format:

19466

How do I convert one or the other to make this comparison?

Thank you in advance


Accepted Solutions
Solution
‎04-18-2012 01:23 PM
Respected Advisor
Posts: 3,156

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

  if datepart( recalldate1)>date365 then delete;

Haikuo

View solution in original post


All Replies
Solution
‎04-18-2012 01:23 PM
Respected Advisor
Posts: 3,156

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

  if datepart( recalldate1)>date365 then delete;

Haikuo

Respected Advisor
Posts: 3,156

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

Update:

or if ' recalldate1' is character variable, then:

datepart(input( recalldate1 ,datetime20.)) >date365 then delete;

Haikuo

Contributor
Posts: 41

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

Thanks Hai.kuo.  Would you know how to do this within a PROC SQL:

PROC SQL;

CREATE TABLE PX_RECALL_1 AS

SELECT * FROM

(SELECT SUM(UNITS) AS RECALL1_UNITS

FROM

PL.TREATMENT_PLANS_2012_04_11

WHERE RECALLTYPE='PX'

AND RECALLDATE1<=SYSDATE+365);

RUN;

It doesn't recognize sysdate.

 

ERROR: The following columns were not found in the contributing tables: SYSDATE.

Respected Advisor
Posts: 3,156

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

if sysdate is a SAS table variable, then you don't have it.

If what you are trying to do is to extract the SAS session starting date, then use &sysdate,

if what you need is the today's date, then use today() or date()

Haikuo

Contributor
Posts: 41

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

Thank you Haikuo!

Super User
Posts: 19,822

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

sysdate will be a date variable as will today() and date(), you'll still need to convert recalldate1 to a date format using datepart

ie

AND datepart(RECALLDATE1)<=(&SYSDATE+365)

Contributor
Posts: 41

Re: Converting 12OCT2012:00:00:00 to SAS numeric date

Thanks Reeza!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 314 views
  • 0 likes
  • 3 in conversation