BookmarkSubscribeRSS Feed

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

5 REPLIES 5
Kurt_Bremser
Super 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.

ballardw
Super User

@Kurt_Bremser 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.

PeterClemmensen
Tourmaline | Level 20

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.));
WarrenKuhfeld
Ammonite | Level 13

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.

Tom
Super User Tom
Super 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;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 14094 views
  • 5 likes
  • 6 in conversation