BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PierreYvesILY
Pyrite | Level 9

dear SAS experts,

 

I need to write a simple macro to calculate:

  • the current date
  • the day before the current date

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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);
PierreYvesILY
Pyrite | Level 9
thanks a lot
Kurt_Bremser
Super User

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.

PierreYvesILY
Pyrite | Level 9
Danke dir

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 382 views
  • 2 likes
  • 3 in conversation