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

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);

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
%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;

View solution in original post

5 REPLIES 5
Suzy_Cat
Pyrite | Level 9

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;

novinosrin
Tourmaline | Level 20
%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;
Suzy_Cat
Pyrite | Level 9
Super... it worked like a gem!

had thought so and tried %sysfun c(intnx(week1.1,today(),0),date9.) but not on today()
CurtisMackWSIPP
Lapis Lazuli | Level 10

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);
Suzy_Cat
Pyrite | Level 9
Thank you guys for the quick and professional fix 🙂

really appreciated !

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register 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
  • 5 replies
  • 1343 views
  • 2 likes
  • 3 in conversation