DATA Step, Macro, Functions and more

Macro to Retrieve Current Date

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Macro to Retrieve Current Date

Hello,

 

I have the macro below which I believe is correct, but I get the error message shown below. When I googled the error message, some authors said a semicolon was missing, but adding that still resulted in the error.

 

I am running SAS 9.4 and receive this error on both Base SAS and SAS EG. 

 

Please advise on how to avoid the error. 

 

Thank you. 

 

%macro currdate;
%qtrim(%qleft(%qsysfunc(date(),worddate18.)));
%mend currdate;

Capture.PNG


Accepted Solutions
Solution
‎02-22-2018 08:05 PM
PROC Star
Posts: 2,226

Re: Macro to Retrieve Current Date

[ Edited ]
Posted in reply to dhrumil_patel

Your code works as intended and the macro call returns a string.

 

You must use that string somehow, for example:

 

%let d = %currdate;

View solution in original post


All Replies
Valued Guide
Posts: 559

Re: Macro to Retrieve Current Date

Posted in reply to dhrumil_patel

The macro processor is a code generator so the line of code you are executing returns a date which SAS then tries to execute and which is, of course, invalid.

 

If you want a macro to return today's date like a function then you could do this

 

%macro currdate;
%let thisday=%qtrim(%qleft(%qsysfunc(date(),worddate18.)));
&thisday
%mend currdate;

%let myday=%currdate;
%put &myday;

Of course there's no need to do that since you can simply use the date function outside a macro anyway....

Solution
‎02-22-2018 08:05 PM
PROC Star
Posts: 2,226

Re: Macro to Retrieve Current Date

[ Edited ]
Posted in reply to dhrumil_patel

Your code works as intended and the macro call returns a string.

 

You must use that string somehow, for example:

 

%let d = %currdate;

Contributor
Posts: 28

Re: Macro to Retrieve Current Date

Thanks Chris.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 90 views
  • 1 like
  • 3 in conversation