Hello
I have the following problem-
I want to run sas code that will run in following way-
If permanent table r_r.cars was lastly updated Today (Day of running=Day of last update of table) then program will not run.
Else (If permanent table r_r.cars was lastly updated before today) then program will run.
What is the way to do it please?
You could try something like the following:
%macro drive(dsn);
%let dsid = %sysfunc(open(&dsn));
%let last_mod = %sysfunc(datepart(%sysfunc(attrn(&dsid, modte))));
%let today=%sysfunc(today());
%let rc = %sysfunc(close(&dsid));
%if &today ne &last_mod %then %do;
%include 'place file here that contains program to run';
%end;
%else %put updated date for &dsn matches todays date of %sysfunc(putn(&today,date9.));
%mend drive;
%drive(r_r.cars)
I found following solution
proc sql noprint;
select datepart(modate)
into :last_update
from dictionary.tables
where libname='R_R'
and memname='CARS';
quit;
%put &=last_update;
%macro run_if_needed;
%if &last_update ne %sysfunc(today()) %then %do;
%put Table not updated today - program will run;
/* your program here */
%end;
%else %do;
%put Table already updated today - program will NOT run;
%end;
%mend run_if_needed; %run_if_needed;
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.