Hello All,
I am running the following queries to get '01-JAN-2022' and '31-MAR-2022' as the first and last day of the first quarter of 2022 (which will be used later to find the number of the days in that quarter - I will use a loop to find each quarter number of days)
%LET QUARTER_START = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(QTR, '01-JAN-2022'.D, 0, B), DATE11.)' "));
%LET QUARTER_END = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(QTR, '01-JAN-2022'.D, 0, E), DATE11.)' "));
However, these do not work and return an error. I was wondering if you could share your insights on this issue. Thank you in advance!
Why so complicated?
%let quarter_start = %sysfunc(intnx(qtr,'01jan2022'd,0,b));
%let quarter_end = %sysfunc(intnx(qtr,'01jan2022'd,0,e));
The macro variables can be used in place of any SAS date value in calculations and comparisons.
Why so complicated?
%let quarter_start = %sysfunc(intnx(qtr,'01jan2022'd,0,b));
%let quarter_end = %sysfunc(intnx(qtr,'01jan2022'd,0,e));
The macro variables can be used in place of any SAS date value in calculations and comparisons.
First thing, any time you get an error, provide the LOG with the code and the error(s). Quite often SAS provides diagnostic characters and messages that are actually quite helpful. Copy the text, on the forum open a text box with the </> icon and paste the text to preserve formatting of the text.
Such as:
138 %LET QUARTER_START = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(QTR, '01-JAN-2022'.D, 0, B), 138! DATE11.)' ")); ERROR: Argument 2 to function INTNX 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.
I have no idea why you are including quotes and the dequote function as that is adding problems. Second, there is no dot in a date value. Consider:
%LET QUARTER_START = %SYSFUNC(INTNX(QTR,'01JAN2022'D, 0, B), DATE11.); %put Quarter_start is &quarter_start.;
Second, if you want to know the number of days then there is no need to create formatted values as that will just add complexity to anything resembling an Intck call or subtraction
%let days= %eval( %SYSFUNC(INTNX(QTR,'01JAN2022'D, 0, E))-%SYSFUNC(INTNX(QTR,'01JAN2022'D, 0, B)) ); %put Days is &days.;
/* or */
%let days2= %sysfunc(intck(day, %SYSFUNC(INTNX(QTR,'01JAN2022'D, 0, b)),%SYSFUNC(INTNX(QTR,'01JAN2022'D, 0, e))));
%put Days2 is &days2.;
Though you may want to consider where the ends actually belong for the total.
@Emoji wrote:
I am running the following queries to get '01-JAN-2022' and '31-MAR-2022' as the first and last day of the first quarter of 2022 (which will be used later to find the number of the days in that quarter - I will use a loop to find each quarter number of days)
If you want the number of days in a quarter, why would you use a loop, when subtraction works fine? Adding on to @Kurt_Bremser 's answer, you can do this:
%let days_in_quarter=%eval(&quarter_end-&quarter_start+1);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.