BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Emoji
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

Emoji
Fluorite | Level 6
Thanks a lot. It worked.
ballardw
Super User

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.

 

PaigeMiller
Diamond | Level 26

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

 

 

 

 

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 550 views
  • 1 like
  • 4 in conversation