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
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
Kevin,
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;
run;
Then just refer to your macro variable as needed in your subsequent DATA step and LABEL statements.
Good luck.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.