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
Rhodochrosite | Level 12

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5 replies
  • 12913 views
  • 5 likes
  • 6 in conversation