06-27-2014 10:54 AM
I am really struggling to get the first day of year in date9. format into a variable.
Can someone please tell me what i am doing wrong here and maybe what would be best.
%let date_range_min = %sysfunc(mdy(1,1,year(date())));
ERROR: Required operator not found in expression: year(date())
ERROR: Argument 3 to function MDY referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
06-27-2014 10:59 AM
Eerrm, the first day of the year is 01, why do you need to do any of that. If you want to substr from a date then do:
and you can put a % before the substr for macro.
mdy is to create dates not extract from them.
06-27-2014 11:16 AM
Obviously you will have better ways to do it, but that is OT. For the one you have, You will need %sysfunc for every SAS functions that you used in the macro expressions:
%let date_range_min = %sysfunc(mdy(1,1,%sysfunc(year(%sysfunc(date())))));
06-27-2014 11:49 AM
Let me clarify what i am trying to do. I need to get the first day of the the current year into a variable in the date9. format. The code from Hai_kuo works to get the date value into the variable but not in a date9. format. I am very new to SAS so if there is a more efficient way to get their I would love to learn it. There is so much that i don't know about this software still.
Thank you all for the quick responses
06-27-2014 12:40 PM
%let date_range_min = %sysfunc(intnx(year,"&sysdate9"d,0, b), date9.);
Doing so, you only need to call a SAS function once, and you get to use an existing macro variable that has the system initiating date (be aware of that though). or something I would cal it cheating:
%let date_range_min =01JAN%sysfunc(year("&sysdate"d));
06-27-2014 01:34 PM
This is beautifully simple. I love efficient code. Thank you everyone for helping me here. I did not realize format was an option of the sysfunc command. I love it.
Need further help from the community? Please ask a new question.