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.
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.
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;
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
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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.