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.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3516 views
  • 6 likes
  • 3 in conversation