BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TurnTheBacon
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

1 REPLY 1
ballardw
Super User

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.


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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