BookmarkSubscribeRSS Feed
Brandon16
Obsidian | Level 7
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?
10 REPLIES 10
Kurt_Bremser
Super User

You have 4 opening, but 6 closing parenthesis.

Try this:

%let datemonth=%sysfunc(intnx(month,%sysfunc(today()),-1),date9.);
%put &datemonth;
Astounding
PROC Star

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

Brandon16
Obsidian | Level 7
The dataset is named by date depending on when it was created which is why the day can change.
Astounding
PROC Star

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.

Brandon16
Obsidian | Level 7
I still can't get it to work. When I key in the %let date manually, it works as expected. As soon as I revert to the Macro, it doesn't match. No idea why.
Tom
Super User Tom
Super User

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.

 

ballardw
Super User

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

Brandon16
Obsidian | Level 7
Dartmouth was a typo sorry.

I have a proc tabulate and class displays as expected when NOT using the automated Macro, however when I try to use the automated Macro, the class is aggregated up as a total

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
  • 10 replies
  • 1497 views
  • 0 likes
  • 5 in conversation