You have 4 opening, but 6 closing parenthesis.
Try this:
%let datemonth=%sysfunc(intnx(month,%sysfunc(today()),-1),date9.);
%put &datemonth;
Assuming you balance the parentheses:
%let Dartmouth =%sysfunc(intnx(month,%sysfunc(today()), -1),date9.);
You still haven't told us why the program should return a particular day of the month instead of the 1st day of the month. What reason is there for picking the 8th or the 12th instead of the 1st?
Taking a wild stab at the reason, that it should be the same day of the month as when you run the program, here is something you can add:
%let Dartmouth =%sysfunc(intnx(month,%sysfunc(today()),-1, same),date9.);
For that, you don't need a program. There is an automatic macro variable (you already have it) named &SYSDATE9 that contains that exact information.
Then post the log of the method that does not work as expected. Use the {i} icon for this.
Are you really creating a macro variable named Dartmouth ?
Make sure you reference the same macro variable you create.
If you are running the %LET inside of a macro then make sure to define the macro variable as global before creating it or else it will be local and disappear when the macro finishes running.
@Brandon16 wrote:
Hi,
Currently within my SAS code there is a date macro
%let datemonth =04jan2018
Next month it could read
%let datemonth =12feb2018
So the day of the month changes. My macro for automation doesn't seem to work for this reason I think when I write this
%let Dartmouth =%sysfunc(intnx(month,%sysfunc(today())),-1),date9.));
Any ideas how to correct the macro please?
You should show how code is currently actually using the macro variable DATEMONTH (likely not Dartmouth).
The %sysfunc approach is going to yield the unformatted numeric version of the date such as 21227 for 12Feb2018, not the DATE9 version.
Also
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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: