DATA Step, Macro, Functions and more

ERROR: Expected close parenthesis after macro function invocation not found.

Reply
anonymous_user
Posts: 0

ERROR: Expected close parenthesis after macro function invocation not found.

Hi,

 

I get the error message when I run the macro below, can someone please advise what im doing wrong please?

 

%let startmonth=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,B)),date9.);
%let endmonth=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,E)),date9.);

Super User
Posts: 7,854

Re: ERROR: Expected close parenthesis after macro function invocation not found.

Posted in reply to anonymous_user

Very simple. Just count your opening parenthesis vs closing parenthesis.

 

PS Enterprise Guide will show you pairs of brackets when you place the cursor before an opening or after a closing bracket.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: ERROR: Expected close parenthesis after macro function invocation not found.

Posted in reply to KurtBremser

KurtBremser wrote:

Very simple. Just count your opening parenthesis vs closing parenthesis.

 

PS Enterprise Guide will show you pairs of brackets when you place the cursor before an opening or after a closing bracket.


And in BASE SAS Enhanced editor Ctrl+( or Ctrl+) with find the matching bracket if any as the interpretter is seeing the code. Note that the match may not be the one you need, just the match as the code you have written. If no result then no match.

PROC Star
Posts: 765

Re: ERROR: Expected close parenthesis after macro function invocation not found.

Posted in reply to anonymous_user

Try this

 


%let startmonth=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,B)),date9.));
%let endmonth=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,E)),date9.));
SAS Super FREQ
Posts: 305

Re: ERROR: Expected close parenthesis after macro function invocation not found.

Posted in reply to anonymous_user

Personally, I would do things like this in a DATA _NULL_ step and avoid all of the macro functions.  Then use SYMPUTX to create macro variables.

Super User
Super User
Posts: 7,076

Re: ERROR: Expected close parenthesis after macro function invocation not found.

Posted in reply to anonymous_user

You have six ( and only five ).

You can simplify your code by eliminating the unneeded PUTN() function calls since you can pass the format to the %SYSFUNC() call.

You should also calculate TODAY only once to eliminate possiblity of setting start and end to different months if you are unlucky in when your code runs.  

 

If you want to avoid macro variable clutter you can reuse STARTMONTH to temporarily store today's date and then use STARTMONTH to find ENDMONTH, just remember to adjust the INTNX() offset appropriately.

 

 

%let startmonth=%sysfunc(today(),date9);
%let startmonth=%sysfunc(intnx(month,"&startmonth"d,-1,B),date9);
%let endmonth=%sysfunc(intnx(month,"&startmonth"d,0,E),date9);

Or just use a data step.

data _null_;
  today=today();
  call symputx('startmonth',put(intnx('month',today,-1,'B'),date9.));
  call symputx('endmonth',put(intnx('month',today,-1,'E'),date9.));
run;

 

Ask a Question
Discussion stats
  • 5 replies
  • 451 views
  • 5 likes
  • 6 in conversation