BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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?

 

 

2 REPLIES 2
russt_sas
SAS Employee

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)

Ronein
Onyx | Level 15

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; 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 281 views
  • 1 like
  • 2 in conversation