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


I am really struggling to get the first day of year in date9. format into a variable.

Can someone please tell me what i am doing wrong here and maybe what would be best.


my code

%let date_range_min = %sysfunc(mdy(1,1,year(date())));

Log error

ERROR: Required operator not found in expression: year(date())
ERROR: Argument 3 to function MDY 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.




Accepted Solutions
Ammonite | Level 13

Just add date9. in the syntax to get the desired result.

%let date_range_min = %sysfunc(mdy(1,1,%sysfunc(year(%sysfunc(date())))),date9.);

View solution in original post

Diamond | Level 26 RW9
Diamond | Level 26

Eerrm, the first day of the year is 01, why do you need to do any of that.  If you want to substr from a date then do:


and you can put a % before the substr for macro.

mdy is to create dates not extract from them.

Ammonite | Level 13

%let date_range_min=%sysfunc(mdy(1,1,2014),date9.);

Onyx | Level 15

Obviously you will have better ways to do it, but that is OT. For the one you have, You will need %sysfunc for every SAS functions that you used in the macro expressions:

%let date_range_min = %sysfunc(mdy(1,1,%sysfunc(year(%sysfunc(date())))));


Obsidian | Level 7

Let me clarify what i am trying to do.  I need to get the first day of the the current year into a variable in the date9. format.  The code from Hai_kuo works to get the date value into the variable but not in a date9. format.  I am very new to SAS so if there is a more efficient way to get their I would love to learn it.   There is so much that i don't know about this software still.



Thank you all for the quick responses

Ammonite | Level 13

Just add date9. in the syntax to get the desired result.

%let date_range_min = %sysfunc(mdy(1,1,%sysfunc(year(%sysfunc(date())))),date9.);

Lapis Lazuli | Level 10

%let begin_day=%sysfunc(putn(%sysfunc(intnx(year, %sysfunc(today()),0, b)),date9.));

Onyx | Level 15

I would use the following to extract the first day of current year: (to , putn() is abundant here):

%let date_range_min = %sysfunc(intnx(year,"&sysdate9"d,0, b), date9.);

Doing so, you only need to call a SAS function once, and you get to use an existing macro variable that has the system initiating date (be aware of that though). or something I would cal it cheating:

%let date_range_min =01JAN%sysfunc(year("&sysdate"d));

Good Luck,


Obsidian | Level 7

This is beautifully simple.  I love efficient code.  Thank you everyone for helping me here.   I did not realize format was an option of the sysfunc command.  I love it.

Super User

Just because there's more than one way Smiley Happy

%let date_range_min = %sysfunc(intnx(year, %sysfunc(date()), 0, b), date9.);

%put &date_range_min.;


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


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
  • 9 replies
  • 6 in conversation