BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 809 views
  • 6 likes
  • 6 in conversation