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.);
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.
@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.
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.));
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.
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;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: