Happy Friday!
i need set up a program automatically run data test1 has been updated last Sunday.
below attached are the code i can not yet make it work. have tried different variations on condition (%if &&CreatedDate_&ds.=intnx('week1.1',today(),0) %then %do;) but issue always lies with intnx('week1.1',today(),0)
Any suggestions?
data test1;
A="this is a test data!";
TodayD=today();
format TodayD date9.;
run;
%macro check_DS_CRDATE(lib,DS);
proc contents data=&lib..&ds. noprint out=DS_Date (keep= MEMNAME MEMLABEL CRDATE MODATE); run;
proc sql noprint;
select distinct CRDATE, datepart(CRDATE)
into : CreatedTime_&ds., :CreatedDate_&ds.
from DS_Date;
%put data &ds. was created at =&&CreatedTime_&ds.;
%put data &ds. was created on =&&CreatedDate_&ds.;
%if &&CreatedDate_&ds.=intnx('week1.1',today(),0) %then %do;
data test_successful;
ref=today();
A="Great effort!";
LastSunday=intnx('week1.1',ref,0);
run;
%end;
run;
%mend check_DS_CRDATE;
%check_DS_CRDATE(work, test1);
%if &&CreatedDate_&ds.=%sysfunc(intnx(week1.1,%sysfunc(today()),0)) %then %do;
Syntax should be :
%sysfunc(intnx(week1.1,%sysfunc(today()),0))
Test:
%let LastSunday= %sysfunc(intnx(week1.1,%sysfunc(today()),0),date9.);
%put LastSunday=&LastSunday;
while tested on intnx('week1.1',today(),0), it returned a numeric value as LastSunday.
data test;
LastSunday=intnx('week1.1',today(),0);
format _all_ date9.;
put (_all_)(=/);
run;
%if &&CreatedDate_&ds.=%sysfunc(intnx(week1.1,%sysfunc(today()),0)) %then %do;
Syntax should be :
%sysfunc(intnx(week1.1,%sysfunc(today()),0))
Test:
%let LastSunday= %sysfunc(intnx(week1.1,%sysfunc(today()),0),date9.);
%put LastSunday=&LastSunday;
Your main problem was trying to call INTNX in open code. You must wrap in in $SYSFUNC for it to work. Same is true of the TODAY functions. Give this a try:
data test1;
A="this is a test data!";
TodayD=today();
format TodayD date9.;
run;
%macro check_DS_CRDATE(lib,DS);
proc contents data=&lib..&ds. noprint out=DS_Date (keep= MEMNAME MEMLABEL CRDATE MODATE); run;
proc sql noprint;
select distinct CRDATE, datepart(CRDATE)
into :CreatedTime_&ds., :CreatedDate_&ds.
from DS_Date;
quit;
%put data &ds. was created at =&&CreatedTime_&ds.;
%put data &ds. was created on =&&CreatedDate_&ds.;
%let tday = %sysfunc(intnx(%str(week1.1),%sysfunc(today()),0));
%put tday = &tday;
%if &&CreatedDate_&ds.=%sysfunc(intnx(%str(week1.1),%sysfunc(today()),0)) %then %do;
data test_successful;
ref=today();
A="Great effort!";
LastSunday=intnx('week1.1',ref,0);
quit;
%end;
%mend check_DS_CRDATE;
%check_DS_CRDATE(work, test1);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.