BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shrutibhatnagar
Obsidian | Level 7
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data testout;
74 set grocery_coupons(keep= couponexpiry);
75 today=today();
76 format today date9.;
77 format coupon_issuance_date date9.;
78 mon_diff_coupexp=intck('month',couponexpiry,today);
79 week_diff_coupexp=intck('week',couponexpiry,today);
80 day_diff_coupexp=intck('day',couponexpiry,today);
81
82 /*from 31-Mar-14*/
83 Day='31-Mar-14'd;
84 mon_diff_coupexp1=intck('month',couponexpiry,day);
85 week_diff_coupexp1=intck('week',couponexpiry,day);
86 day_diff_coupexp1=intck('day',couponexpiry,day);
87
88 /*question2*/
89 coupon_issuance_date=intnx('month',couponexpiry,3);
90 /*question3 -30-sep-14*/
91 day2='30-sep-14'd;
92 day_diff_coupexp2=datdif(day2,couponexpiry,'30/act');
93 run;
 
NOTE: Invalid argument to function DATDIF(19996,19774,'30/act') at line 92 column 19.
couponexpiry=20FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=261
day_diff_coupexp=1826 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=6 day_diff_coupexp1=39 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=1
NOTE: Invalid argument to function DATDIF(19996,19775,'30/act') at line 92 column 19.
couponexpiry=21FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=261
day_diff_coupexp=1825 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=6 day_diff_coupexp1=38 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=2
NOTE: Invalid argument to function DATDIF(19996,19776,'30/act') at line 92 column 19.
couponexpiry=22FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=261
day_diff_coupexp=1824 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=6 day_diff_coupexp1=37 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=3
NOTE: Invalid argument to function DATDIF(19996,19777,'30/act') at line 92 column 19.
couponexpiry=23FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1823 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=36 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=4
NOTE: Invalid argument to function DATDIF(19996,19778,'30/act') at line 92 column 19.
couponexpiry=24FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1822 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=35 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=5
NOTE: Invalid argument to function DATDIF(19996,19779,'30/act') at line 92 column 19.
couponexpiry=25FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1821 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=34 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=6
NOTE: Invalid argument to function DATDIF(19996,19780,'30/act') at line 92 column 19.
couponexpiry=26FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1820 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=33 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=7
NOTE: Invalid argument to function DATDIF(19996,19781,'30/act') at line 92 column 19.
couponexpiry=27FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1819 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=32 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=8
NOTE: Invalid argument to function DATDIF(19996,19782,'30/act') at line 92 column 19.
couponexpiry=28FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1818 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=31 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=9
NOTE: Invalid argument to function DATDIF(19996,19782,'30/act') at line 92 column 19.
couponexpiry=28FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1818 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=31 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=10
NOTE: Invalid argument to function DATDIF(19996,19783,'30/act') at line 92 column 19.
couponexpiry=01MAR2014 today=20FEB2019 coupon_issuance_date=01JUN2014 mon_diff_coupexp=59 week_diff_coupexp=260
day_diff_coupexp=1817 Day=19813 mon_diff_coupexp1=0 week_diff_coupexp1=5 day_diff_coupexp1=30 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=11
NOTE: Invalid argument to function DATDIF(19996,19784,'30/act') at line 92 column 19.
couponexpiry=02MAR2014 today=20FEB2019 coupon_issuance_date=01JUN2014 mon_diff_coupexp=59 week_diff_coupexp=259
day_diff_coupexp=1816 Day=19813 mon_diff_coupexp1=0 week_diff_coupexp1=4 day_diff_coupexp1=29 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=12
NOTE: Invalid argument to function DATDIF(19996,19785,'30/act') at line 92 column 19.
couponexpiry=03MAR2014 today=20FEB2019 coupon_issuance_date=01JUN2014 mon_diff_coupexp=59 week_diff_coupexp=259
day_diff_coupexp=1815 Day=19813 mon_diff_coupexp1=0 week_diff_coupexp1=4 day_diff_coupexp1=28 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=13
NOTE: Invalid argument to function DATDIF(19996,19786,'30/act') at line 92 column 19.
couponexpiry=04MAR2014 today=20FEB2019 coupon_issuance_date=01JUN2014 mon_diff_coupexp=59 week_diff_coupexp=259
day_diff_coupexp=1814 Day=19813 mon_diff_coupexp1=0 week_diff_coupexp1=4 day_diff_coupexp1=27 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=14
NOTE: Invalid argument to function DATDIF(19996,19787,'30/act') at line 92 column 19.
couponexpiry=05MAR2014 today=20FEB2019 coupon_issuance_date=01JUN2014 mon_diff_coupexp=59 week_diff_coupexp=259
day_diff_coupexp=1813 Day=19813 mon_diff_coupexp1=0 week_diff_coupexp1=4 day_diff_coupexp1=26 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=15
NOTE: Invalid argument to function DATDIF(19996,19774,'30/act') at line 92 column 19.
couponexpiry=20FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=261
day_diff_coupexp=1826 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=6 day_diff_coupexp1=39 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=16
NOTE: Invalid argument to function DATDIF(19996,19776,'30/act') at line 92 column 19.
couponexpiry=22FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=261
day_diff_coupexp=1824 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=6 day_diff_coupexp1=37 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=17
NOTE: Invalid argument to function DATDIF(19996,19777,'30/act') at line 92 column 19.
couponexpiry=23FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1823 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=36 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=18
NOTE: Invalid argument to function DATDIF(19996,19778,'30/act') at line 92 column 19.
couponexpiry=24FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1822 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=35 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=19
NOTE: Invalid argument to function DATDIF(19996,19779,'30/act') at line 92 column 19.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
couponexpiry=25FEB2014 today=20FEB2019 coupon_issuance_date=01MAY2014 mon_diff_coupexp=60 week_diff_coupexp=260
day_diff_coupexp=1821 Day=19813 mon_diff_coupexp1=1 week_diff_coupexp1=5 day_diff_coupexp1=34 day2=19996 day_diff_coupexp2=.
_ERROR_=1 _N_=20
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
276 at 78:18 276 at 79:19 276 at 80:18 276 at 84:19 276 at 85:20 276 at 86:19 276 at 89:22
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1680 at 92:19
NOTE: There were 1680 observations read from the data set WORK.GROCERY_COUPONS.
NOTE: The data set WORK.TESTOUT has 1680 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.36 seconds
cpu time 0.37 second
 GETTING WARNINGS THIS WAY NOT GETTING RESULT FOR DATDIF FUNCTION 
1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

It may be that you don't have real SAS dates or that you have incorrectly used the datdif function.

data _null;
	mydate=DATDIF(19996,19779,'30/act');
	put mydate;
	mydate=datdif('01JUN1996'd,'01SEP1977'd,30/act);
	put mydate;

run;

It is hard to tell with so much noise from the code.  Make a simple test dataset and get the logic to work then add back into that code all the extra stuff.

View solution in original post

10 REPLIES 10
andreas_lds
Jade | Level 19

Always post code and log using the "Insert [SAS] Code" functions -> running man icon! This is hardly readable mess.

 

The function is documented here. It seems that "30/act" is not a valid value for the third parameter.

Shrutibhatnagar
Obsidian | Level 7

same error with 30/360 also .

Shrutibhatnagar
Obsidian | Level 7

my answer is coming in negative values and it is saying that middle argument is invalid .

andreas_lds
Jade | Level 19

Please check your data. Afaik the only invalid middle-argument (aka end-date) is a missing value.

Shrutibhatnagar
Obsidian | Level 7

then how come it is giving an answer . the only problem is it gives a nagative integer with warning .

andreas_lds
Jade | Level 19

Please post the log of your last run and show data.

Shrutibhatnagar
Obsidian | Level 7

log and data are as follows log.PNG

andreas_lds
Jade | Level 19

Sorry, but screenshots and Excel-files are of no use. See the message of @RW9, it explains how to post data in usable form.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post example test data in the form of a datastep:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

We cannot solve data issues without seeing the data!

 

From the log:

couponexpiry=20FEB2014

That looks like text, when you compare it to the other 'date' in your code:

day2=19996

Both values have to be valid dates.

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

It may be that you don't have real SAS dates or that you have incorrectly used the datdif function.

data _null;
	mydate=DATDIF(19996,19779,'30/act');
	put mydate;
	mydate=datdif('01JUN1996'd,'01SEP1977'd,30/act);
	put mydate;

run;

It is hard to tell with so much noise from the code.  Make a simple test dataset and get the logic to work then add back into that code all the extra stuff.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 10 replies
  • 2672 views
  • 0 likes
  • 4 in conversation