BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6

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


2 REPLIES 2
Reeza
Super User

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

Astounding
PROC Star

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-2024.png

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
  • 2 replies
  • 791 views
  • 0 likes
  • 3 in conversation