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

Hello SAS users,

I am doing a condition check here, if the code run day is sunday i want to take the sunday dt and output in  'm/dd/yyyy' format. If it is not sunday I want to take the run date and do a day -1 and output in  'mm/dd/yyyy' as well.

I am getting the below error and not sure what I am doing wrong.

ERROR: Expected close parenthesis after macro function invocation not found.

ERROR: The function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function has too few

Would anyone have any idea?

%Macro c;
Data _null_;

%If %sysfunc(weekday(%sysfunc(today()))) = 1 %then %Let dt = %str(%')%sysfunc(putn(%sysfunc(today()),mmddyys10.))%str(%'); 
%else %Let dt = %str(%')%sysfunc(putn(%sysfunc(today(),-1),mmddyys10.))%str(%');
Run;

%Put dt= &dt.;
%Mend c;
%c;

arguments.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Don't need a macro either as there is no macro logic involved.

You can make the nested %SYSFUNC() calls easier by first getting the numeric version of today's date.

%let dt=%sysfunc(today());

%let dt=%str(%')%sysfunc(putn(&dt-(1=%sysfunc(weekday(&dt))),mmddyys10.))%str(%');

Note the %EVAL is not required in the arguments passed to the function that %SYSFUNC() is calling.  The function can evaluate expressions just as it does when called in a data step.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

If you are running a data step they why are you bothering with macro statements?

%Macro c;
Data _null_;

%If %sysfunc(weekday(%sysfunc(today()))) = 1 %then %Let dt = %str(%')%sysfunc(putn(%sysfunc(today()),mmddyys10.))%str(%'); 
%else %Let dt = %str(%')%sysfunc(putn(%sysfunc(today(),-1),mmddyys10.))%str(%');
Run;

%Put dt= &dt.;
%Mend c;
%c;

data _null_;

  call symputx('dt',"'"||put(today()-(1 = weekday(today())),mmddyys10.)||"'");

run;

Haikuo
Onyx | Level 15

I second Tom. On the other hand, you don't need data step to make it happen either:

%Macro c;

/*Data _null_;*/

%If %sysfunc(weekday(%sysfunc(today()))) = 1 %then %Let dt = %str(%')%sysfunc(putn(%sysfunc(today()),mmddyy10.))%str(%');

%else %Let dt = %str(%')%sysfunc(putn(%eval(%sysfunc(today())-1),mmddyy10.))%str(%');

/*Run; */

%Put dt= &dt.;

%Mend c;

%c

The only thing was missing is %eval.

Haikuo

Tom
Super User Tom
Super User

Don't need a macro either as there is no macro logic involved.

You can make the nested %SYSFUNC() calls easier by first getting the numeric version of today's date.

%let dt=%sysfunc(today());

%let dt=%str(%')%sysfunc(putn(&dt-(1=%sysfunc(weekday(&dt))),mmddyys10.))%str(%');

Note the %EVAL is not required in the arguments passed to the function that %SYSFUNC() is calling.  The function can evaluate expressions just as it does when called in a data step.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 4147 views
  • 6 likes
  • 3 in conversation