Hello,
I want to make the difference between date in year ( date format is mmddyy10.)
I write this program but it does not work
data ageyear;
set inception;
Age = yrdif(Inception_date, sas_date, 'AGEYear');
run;
I have find the problem. thanks for your help.
Age = yrdif(Inception_date, sas_date,'Actual');
I write this program but it does not work
It is never sufficient to say "it does not work" and stop there. If there are errors in the log, SHOW US the log. If the output is incorrect, SHOW US the incorrect output and explain why it is incorrect. Please provide that information.
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.
@sasphd wrote:
Hello,
I want to make the difference between date in year ( date format is mmddyy10.)
I write this program but it does not work
data ageyear; set inception; Age = yrdif(Inception_date, sas_date, 'AGEYear'); run;
this is the log error
NOTE: Invalid argument to function YRDIF(9646,9677,'AGEYear') at line 146 column 7.
secid=F000000EU6 DATE=198606 mret=0.006 sas_date=06/30/1986 Inception_date=05/30/1986 Age=.
_ERROR_=1 _N_=1
this is the output
We need to see the ENTIRE log for this SAS data step. In other words, the code and all NOTES, WARNINGs and ERRORs, as they appear in the log. We don't know what the log is reacting to because without that other information, we don't know what line 146 is.
I have find the problem. thanks for your help.
Age = yrdif(Inception_date, sas_date,'Actual');
@sasphd wrote:
I have find the problem. thanks for your help.
Age = yrdif(Inception_date, sas_date,'Actual');
@sasphd :
Problem is the short piece of log you did show us said the error was at line 146, column 7, and changing to 'Actual' doesn't affect what is in column 7. So there was something else wrong.
And again, I ask you to show us the ENTIRE log for this DATA step (and in the future, you need to show us the ENTIRE log without us even asking).
Code from the log as well as the error message. There is something else going on because those numeric values are not the issue. Actual data in the form of a data step such as the following that generates the same error when using the same code.
data example; input sas_date :mmddyy10. Inception_date :mmddyy10.; format sas_date inception_date mmddyy10.; datalines; 06/30/1986 05/30/1986 ;
It is possible that if you copied the line of code with the AGE= yrdif( ) from the internet or some document with formatting like a word processor file that there are invisible formatting characters you don't see that can cause errors.
@sasphd wrote:
Hello,
I want to make the difference between date in year ( date format is mmddyy10.)
I write this program but it does not work
data ageyear; set inception; Age = yrdif(Inception_date, sas_date, 'AGEYear'); run;
AGEYear is not a valid BASIS.
@data_null__ wrote:
@sasphd wrote:
Hello,
I want to make the difference between date in year ( date format is mmddyy10.)
I write this program but it does not work
data ageyear; set inception; Age = yrdif(Inception_date, sas_date, 'AGEYear'); run;
AGEYear is not a valid BASIS.
But, at least in my install, does not throw an error:
205 data example; 206 input sas_date :mmddyy10. Inception_date :mmddyy10.; 207 format sas_date inception_date mmddyy10.; 208 Age = yrdif(Inception_date, sas_date, 'AGEYear'); 209 210 datalines; NOTE: The data set WORK.EXAMPLE has 1 observations and 3 variables.
Either the code ignore the "year" part of "AGEyear" and accepts AGE, or ignores the entire argument and uses the default, which is AGE.
So, @sasphd which version of SAS are your running?
@data_null__ wrote:
@sasphd wrote:
Hello,
I want to make the difference between date in year ( date format is mmddyy10.)
I write this program but it does not work
data ageyear; set inception; Age = yrdif(Inception_date, sas_date, 'AGEYear'); run;
AGEYear is not a valid BASIS.
Problem is, we DO know that the error occurs at line 146 column 7, and the 'AGEYear' is not column 7.
I think the 7 referred to whatever position the YRDIF function Y appears and indicates that one of the parameters is wrong.
Interesting that in my install, SAS 9.4.4 I can place pure garbage in the BASIS option position and not generate any error. Though this version does not return the same value that the AGE does, instead matching the result for ACT. If I use AGExxxxx, where xxxx are just about any characters then apparently the AGE basis is used. Perhaps in this version SAS reads enough to see an option that matches an entry on the Basis list and stop.
277 data example; 278 input sas_date :mmddyy10. Inception_date :mmddyy10.; 279 format sas_date inception_date mmddyy10.; 280 Age = yrdif(Inception_date, sas_date,'gobbledegook'); 281 put age= ; 282 datalines; Age=0.0833333333 NOTE: The data set WORK.EXAMPLE has 1 observations and 3 variables.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.