dear SAS experts,
I need to write a simple macro to calculate:
and use them afterwards in the programm.
I wrote:
/* macro-code fuer den Auswertungstag */
%macro auswert;
%global Date_of_today;
%let Date_of_today=%sysfunc(today());
%mend auswert;
%auswert;
%put &Date_of_today.;
%macro Auswertungstag;
Auswertungstag=&Date_of_today.-1;
%mend Auswertungstag;
%Auswertungstag;
/* Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag */
%put &Auswertungstag.;
but I have this error message in the log:
/* macro-code fuer den Auswertungstag */
27 %macro auswert;
28 %global Date_of_today;
29 %let Date_of_today=%sysfunc(today());
30 %mend auswert;
31 %auswert;
32 %put &Date_of_today.;
21930
33
34 %macro Auswertungstag;
35 Auswertungstag=&Date_of_today.-1;
36 %mend Auswertungstag;
37 %Auswertungstag;
NOTE: Line generated by the invoked macro "AUSWERTUNGSTAG".
37 Auswertungstag=&Date_of_today.-1;
______________
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
38
39 %put &Auswertungstag.;
WARNING: Apparent symbolic reference AUSWERTUNGSTAG not resolved.
&Auswertungstag.
what do I do wrong?
can someone send me the correct script?
thanks a lot for any help
regards
PY
You are missing the %let-statement and %eval - in macro language required to perform calculations. So
Auswertungstag=&Date_of_today.-1;
should be
%let Auswertungstag= %eval(&Date_of_today.-1);
You are missing the %let-statement and %eval - in macro language required to perform calculations. So
Auswertungstag=&Date_of_today.-1;
should be
%let Auswertungstag= %eval(&Date_of_today.-1);
First of all, these are just simple macro variable assignments, you do not need a macro definition for that.
You can do it in open code:
%let Date_of_today=%sysfunc(today());
%let Auswertungstag=%eval(&Date_of_today.-1);
so you also don't need the %global statement (which is missing in your second macro, causing WARNING: Apparent symbolic reference AUSWERTUNGSTAG not resolved).
If you find you need that repeatedly, put it in your autoexec, or save it as a .sas file to use in a %include.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.