BookmarkSubscribeRSS Feed
mick_g
Calcite | Level 5

Below is the code I am working with:

I am trying to get hdate to be 5 days less than tdate.  or hdate to be 5 days before tdate.

tdate =

PUT(DATEPART(Process_Date), date9.);

Format BDate hDate yymmddp10.;

BDate = intnx('day',date(),-5);

hdate = intnx('day',tdate,-5);

however I get hdate and null.

any advise

3 REPLIES 3
DF
Fluorite | Level 6 DF
Fluorite | Level 6

Hi Mick,

I don't think you were too far from out.  It looks like you've mixed up what the PUT function is doing here - it converts a number to text, based on the specified format, where as you want TDATE to be an actual date value, formatted as Date9.

Try the below (the first bit just makes up some random data):

data testing;

format Process_Date datetime20.;

drop date h m s;

do i = 1 to 100;

    date = intnx('day','01JAN2011'd,365*ranuni(1)+180);

    h = 23*ranuni(2);

    m = 59*ranuni(3);

    s = 59*ranuni(4);

    Process_Date = dhms(date,h,m,s);

    output;

end;

run;

data testing2;

set testing;

format tdate date9.;

format hdate date9.;

format bdate date9.;

tdate = datepart(Process_Date);

bdate = intnx('day',date(),-5);

hdate = intnx('day',tdate,-5);

run;

chang_y_chung_hotmail_com
Obsidian | Level 7

If you have a date value, then you can just subtract 5.

   data _null_;
     p = '24jun2011:08:30:00'dt; /* a datetime value */
     d = datepart(p); /* extract a date */
     h = d - 5; /* five days before the date */

     put p= :datetime9. (d h) (= :date9.);
   run;
   /* on log
   p=24JUN2011 d=24JUN2011 h=19JUN2011
   */

mick_g
Calcite | Level 5

Thank you,

It works!!

It is always something so simple with SAS that catches you.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2158 views
  • 6 likes
  • 3 in conversation