Data _null_;
MyDate = Today();
format MyDate mmddyy10.;
put "Current Date " MyDate;
next_rundate = intnx('week', MyDate, 1,'B');
format next_rundate mmddyy10.
put "next Run Date " next_rundate; /* A - This print correct date after one week in mm/dd/yyyy format*/
run;
/* I want to store value at above line in to below update statement and in database field is date time current below command just store dot (.) in date field - what do I do to convert next_rundate in correct format so I can update thru table */
proc sql;
update lib.table1
set next_rundate = "&next_rundate" DT
where id =&id.;
Run;
This should fix it
intnx('dtweek',datetime(),1,'b')
There's no need for a macro variable if the value is stored in a SAS data set, and you just want to find other dates from it.
You should not need a macro variable or even two steps to do this. Here is how I would do this, although I haven't tested this at all. It may depend on how next_rundate is formatted in lib.table1.
proc sql;
update lib.table1 set next_rundate = intnx('week',today(),1,'b')
where id =&id.;
run;
Thanks Miller for you comment
This gives me date in 01JAN1960:06:21:32 format but not one week after.
also I would need to store that in macro variable because down the road I have some condition to populate
Week after
Month after
Quater after
Year after and save to database so I will have one update statement with value changing for my multiple if conditions.
This should fix it
intnx('dtweek',datetime(),1,'b')
There's no need for a macro variable if the value is stored in a SAS data set, and you just want to find other dates from it.
@dhavalyparikh wrote:
Sorry my bad the command which you sent below that works
intnx('dtweek',datetime(),1,'b')
but now Is there a way I can save this value in a variable and assign it with my update statement?
Explain why you need to save it somewhere, other than in lib.table1 where it is already saved?
Use a CASE for the value:
proc sql;
update lib.table1
set next_rundate = (case
when jtype = "week" then intnx('dtweek',datetime(),1,'b')
when jtype = "year" then intnx('dtyear',datetime(),1,'b')
else .
end)
where id =&id.;
run;
@dhavalyparikh wrote:
That's kind of weird. Now it's giving me 03Jan1960:00:00:00
Can't be.
data _null_;
next_week = intnx('dtweek',datetime(),1,'b');
format next_week e8601dt19.;
put "next week= " next_week;
run;
Log:
68 69 data _null_; 70 next_week = intnx('dtweek',datetime(),1,'b'); 71 format next_week e8601dt19.; 72 put "next week= " next_week; 73 run; next week= 2022-09-04T00:00:00
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 25. Read more here about why you should contribute and what is in it for you!
Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.
Find more tutorials on the SAS Users YouTube channel.