09-01-2011 08:21 AM
We have some test data related to subscribers where we have service date and based on this date, we need to calculate no of years of service.
We are using current month and using a yrdif function, but it kept failing.
If service date and current date are in yyyymmdd format and if service date is greater than current_dt or in less than current_dt, please let me know how to handle so I will not get any spaces in resulting value.
09-01-2011 08:45 AM
A couple of questions:
1. Are you certain that current_dt is a date or might it be a datetime? If it is a datetime, you'll have to enclose it with the datepart() function.
2. What are you trying to output the result to? A text file? A SAS dataset? Your code, at least to the right of the put statement, appears to be correct.
3. What do you want to output when Service_date is gt current date?
You will get a most useful answer if the forum has a better understanding of what you are trying to accomplish.
09-01-2011 09:26 AM
1. yes, it is only date in yyyymmdd format.
2. We are outputting as a character of 7 bytes.
3. if Service date is gt current date, we are making as zero. and if Service date is blank we are defaulting date value to 17000101.
09-01-2011 09:36 AM
Then some of your questions confuse me. 17000101 sure looks like a datetime value, namely July 15, 1960.
If your variables are in fact datetime variables, then you will need to use datepart for one or both variables.
You originally asked: "let me know how to handle so I will not get any spaces in resulting value". Please explain.
And, finally, you are outputting to what? A text file? A SAS dataset? A report?
09-01-2011 12:00 PM
By using the $7. format in your put statement you are corrupting your numeric values. The outout of the put statement is always character so you should be using a proper numeric format to not obscure your result (basically you are rounding the the integer level instead of the the hundreth as you want). To avoid the 'spaces' try using encasing your calculation in a strip().
if mod(day,2)=0 then year=2000; else year=2001;