BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
sasphd
Lapis Lazuli | Level 10

 

 

I have find the problem. thanks for your help. 

Age = yrdif(Inception_date, sas_date,'Actual');

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

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;

 

sasphd
Lapis Lazuli | Level 10

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

sasphd_0-1649348184322.png

this is the output

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
sasphd
Lapis Lazuli | Level 10

 

 

I have find the problem. thanks for your help. 

Age = yrdif(Inception_date, sas_date,'Actual');
PaigeMiller
Diamond | Level 26

@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).

--
Paige Miller
ballardw
Super User

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.

 

data_null__
Jade | Level 19

@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.

ballardw
Super User

@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?

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ballardw
Super User

@PaigeMiller 

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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 11 replies
  • 770 views
  • 7 likes
  • 4 in conversation