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!
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.
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.
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.))";
Thank you Tom and Arthur!
Both of your codes worked beautifully!! Thank you so much for your help. I really appreciate it !!!
Tom,
Your code always seems so slick and simple. Your input is always greatly appreciated !
Kevin
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.
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.
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.