BookmarkSubscribeRSS Feed
robm
Quartz | Level 8

 

 

 

I have a line like this

%LET YEARNOW= %unquote(%str(%'%sysfunc(year(today()), yyyy.)%'));

That throws an error like

ERROR: Required operator not found in expression: today()
ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.

What I am trying to do it get the year from a function so I copied this working one

%LET DATENOW= %unquote(%str(%'%sysfunc(today(), yymmdd10.)%'));


And tried to Dr it up

5 REPLIES 5
Reeza
Super User

You have two functions, Year() and today(). Each requires its own %SYSFUNC. 

 

%let year = %sysfunc(today(), year4.);

 

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

collinelliot
Barite | Level 11
%let yearnow = %sysfunc(year(%sysfunc(today())));
%put &yearNow;
Astounding
PROC Star

I think you're overcomplicating this a bit.  Try it this way:

 

%LET YEARNOW= %unquote(%str(%'%sysfunc(today(), year4)%'));

 

%SYSFUNC lets you control the format of the value it returns.

ballardw
Super User

Every datastep function needs a separate %sysfunc.

Try

 

%let yearnow = %sysfunc(year(%sysfunc(today())));
%put &yearnow;

and

 

%let datenow = %sysfunc(putn(%sysfunc(today()),yymmdd10.));
%put &datenow;

Or move to a data step as much data manipulation in macro language becomes very ugly and sometimes fragile.

 

 

I find that the need to have something like %unquote(%str is an indication that I may want to rethink things.

Astounding
PROC Star

ballardw,

 

It's a question of what you want as the final result.  You will get:

 

2017

 

The added complications that I included will get:

 

'2017'

 

If you want quotes around the final value, you need to jump through the extra hoops.  But if you don't want the quotes, it becomes even simpler:

 

%let yearnow = %sysfunc(today(), year4);

 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 4928 views
  • 0 likes
  • 5 in conversation