SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Using DATA step to manipulate date values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Using DATA step to manipulate date values

I need to do a quick ad-hoc operation in user written code. The program needs to locate row 2, store its variable "from_dttm" minus 1 second into the new variable "newdate", then locate row 4 and put "newdate" into "to_dttm".


I know I'm not handling the date values correctly in the code below, and would appreciate any advice on how to resolve this. Thank you.

data &_output;

  set work.replace;

  format newdate NLDATM21.;

   if _n_ = 2 then do;

       newdate = from_dttm-1;

  end;


   if _n_ = 4 then do;

        to_dttm = newdate;

  end;


run;


Accepted Solutions
Solution
‎10-03-2012 10:25 AM
Super User
Posts: 11,343

Re: Using DATA step to manipulate date values

Posted in reply to TurnTheBacon

to keep the values of newdate across "rows" you need to add a retain statement.

retain newdate . ;

If you need to do this to many records you'll probably need a different approach.


View solution in original post


All Replies
Solution
‎10-03-2012 10:25 AM
Super User
Posts: 11,343

Re: Using DATA step to manipulate date values

Posted in reply to TurnTheBacon

to keep the values of newdate across "rows" you need to add a retain statement.

retain newdate . ;

If you need to do this to many records you'll probably need a different approach.


🔒 This topic is solved and locked.

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

Discussion stats
  • 1 reply
  • 161 views
  • 0 likes
  • 2 in conversation