DATA Step, Macro, Functions and more

%sysfunc Question

Regular Contributor
Posts: 173

%sysfunc Question

Hello Everyone,

I am trying to create a column label as a 3-letter month followed by 2-digit year (i.e. Dec-12).  I currently use this code:

label new_month = "%sysfunc(today(),monname3.)-%sysfunc(today(),year2.)";

The code works as long as I use today().  But I would like to use the 'process_date'(a time stamp date)  instead of today().  I have started by trying out the month portion first.  And it does not seem to work:

label new_month = '"%synfunc(datepart(process_date),monname3.)";

Instead of creating the label 'Dec-12' it is displaying '%synfunc(datepart(process_date),monname3.)' as the label.

I get a warning "Apparent invocation of macro SYNFUNC not resolved".  Does anyone have any suggestions on how I can make the label to show 'Dec-12' using a timestamp date ?

Thank you very munch Smiley Happy

Super User
Posts: 23,773

Re: %sysfunc Question

I would suggest creating a format and then applying the format with putc and sysfunc instead, seems easier to me.

You also have a typo, missing an 's', it should be %sysfunc not %synfunc

Super User
Posts: 6,785

Re: %sysfunc Question


You will need to split up the processing into two steps.  It is not possible to take the value of a DATA step variable, and include it as part of a variable label, all in the same step.  The basic reason for that is that SAS has to compile the LABEL statement before reading in any data, so the data needed to properly define the label doesn't exist at that point.

Once you split this up into two steps, there are a variety of ways to do it so long as PROCESS_DATE is constant.  Probably the easiest is to create a macro variable holding the proper characters to insert into a label:

data _null_;

set have (obs=1 keep=process_date);

** use the DATA step then CALL SYMPUT to create your macro variable ... no %SYSFUNC needed in that case;


Then just refer to your macro variable as needed in your subsequent DATA step and LABEL statements.

Good luck.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation