Help using Base SAS procedures

Proc Format Help! (_Label_)

Reply
Regular Contributor
Posts: 173

Proc Format Help! (_Label_)

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

Regular Contributor
Posts: 173

Re: Proc Format Help! (_Label_)

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.

PROC Star
Posts: 7,467

Re: Proc Format Help! (_Label_)

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.

Super User
Super User
Posts: 7,039

Re: Proc Format Help! (_Label_)

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.))";

Regular Contributor
Posts: 173

Re: Proc Format Help! (_Label_)

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

Super User
Super User
Posts: 7,039

Re: Proc Format Help! (_Label_)

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.

Ask a Question
Discussion stats
  • 5 replies
  • 225 views
  • 6 likes
  • 3 in conversation