BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I am trying to use INTNX function to get one day after  date in start column.

Why am I getting null value ?(In following statement:

OneDay_after_start=INTNX ('day', start, 1);

Data tbl1;
informat start date9. end date9.;
format start date9. end date9.;
input mon start end;
cards;
1812 '21DEC2018'd '21Jan2019'd
1901 '22Jan2019'd '21Feb2019'd
1902 '22Feb2019'd '21Mar2019'd
;
run;


data tbl2;
set tbl1 end=eof;
if eof then output;
OneDay_after_start=INTNX ('day', start, 1);
call symput('xxx1',start);
call symput('xxx2',put(start,date9.));
call symput('xxx3',"'"||put(start,date9.)||"'d");

call symput('www1',OneDay_after_start);
call symput('www2',put(OneDay_after_start,date9.));
call symput('www3',"'"||put(OneDay_after_start,date9.)||"'d");
run;
%put &xxx1.;/*21602*/
%put &xxx2.;/*22FEB2019*/
%put &xxx3.;/*'22FEB2019'dt*/

%put &www1.;/*21603*/
%put &www2.;/*23FEB2019*/
%put &www3.;/*'23FEB2019'dt*/
5 REPLIES 5
Shmuel
Garnet | Level 18

To get the next day date you do

tomorrow = toady +1;

Sas date counts days from 01JAN1960 as zero. You don't need INTNX function.

novinosrin
Tourmaline | Level 20

Hi @Ronein 

 

To your why-

"Hello

I am trying to use INTNX function to get one day after  date in start column.

Why am I getting null value ?(In following statement:

OneDay_after_start=INTNX ('day', start, 1);"

Move your 

OneDay_after_start=INTNX ('day', start, 1);

Before 

if eof then output;

See the below

 

data tbl2;
set tbl1 end=eof;
OneDay_after_start=INTNX ('day', start, 1);
if eof then output;
/*OneDay_after_start=INTNX ('day', start, 1);*/
call symput('xxx1',start);
call symput('xxx2',put(start,date9.));
call symput('xxx3',"'"||put(start,date9.)||"'d");

call symput('www1',OneDay_after_start);
call symput('www2',put(OneDay_after_start,date9.));
call symput('www3',"'"||put(OneDay_after_start,date9.)||"'d");
run;

 

 

ChrisNZ
Tourmaline | Level 20

Also,

1. Use call symputx() for numeric variables to avoid messages in the log.

 

call symputx('xxx1',START)

 

2. Your code is more efficient if you do nothing unless required to:

data TBL2;
  set TBL1 end=EOF;
  if EOF ;
  ONEDAY_AFTER_START=intnx('day', START, 1);
  call symputx()...
run;

3. For even more efficiency and if the table is large, fetch the number of observations and use option FIRSTOBS=

data _null_;
  call symputx('nobs',NOBS);
  stop;
  if 0 then set TBL1 nobs=NOBS;
run;

data TBL2;
  set TBL1 (firstobs=&nobs.);
  ONEDAY_AFTER_START=intnx('day', START, 1);
  call symputx()...
run;

 

Tom
Super User Tom
Super User

If SAS knows the number of observations then you could use POINT=.  Just be careful not to put the data step into an infinite loop.

data x;
  if _n_>1 then stop;
  set sashelp.class point=nobs nobs=nobs;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1443 views
  • 6 likes
  • 6 in conversation