BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6

Hello Everyone,

I am trying to use MMM-YY (Oct-12) as a column lable using proc format.  Using the code below I get

'format mon_yr fmtb.' as the column label.  How can I have the column lable as 'Oct-12' ?

Proc format;

picture fmtb(default=6) other='%b-%y' (datatype = date);

run;

data mtd;

set in1;

mon_yr = today();

format mon_yr fmtb.;

label mtd_total = format mon_yr fmtb.;

run;

Thank you for any input you may have! Smiley Happy

5 REPLIES 5
KevinC_
Fluorite | Level 6

let me make myself a little more clear:   I know I can have

label  mtd_total = 'OCT-12';

but I am trying to automate this process so no manual updates..

Thank you.

art297
Opal | Level 21

Since you are creating a copy of the file anyway, you could create that copy using call execute and include the desired label statement.  e.g.:

Proc format;

  picture fmtb(default=6) other='%b-%y' (datatype = date);

run;

data in1;

  set sashelp.class (rename=(weight=mtd_total));

run;

data _null_;

  call execute('data mtd;set in1;'

  ||'label mtd_total ='

  ||put(today(),fmtb.)

  ||';run;');

run;

Of course, if the file already exists, doing the same thing using proc datasets would be more economical.

Tom
Super User Tom
Super User

You cannot use a format in that way, but you could use it with %SYSFUNC() call.

label mtd_total = "%sysfunc(today(),fmtb.)" ;


Why do you need to define your own format? Why not just build the string from the month and year?

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

KevinC_
Fluorite | Level 6

Thank you Tom and Arthur!

Both of your codes worked beautifully!!  Thank you so much for your help.  I really appreciate it !!! Smiley Happy

Tom,

Your code always seems so slick and simple.  Your input is always greatly appreciated !

Kevin

Tom
Super User Tom
Super User

Thanks.

The key to writing clear maintainable code is to Simplify, Simplify, Simplify.
The key to writing clear maintainable code is to Simplify, Simplify.
The key to writing clear maintainable code is to Simplify.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 849 views
  • 6 likes
  • 3 in conversation