Hello Everyone,
How do I format a numeric field (i.e. 102012) as Oct 2012?
I basically want to show the month (Oct) plus the year (2012). Is this possible?
Thank you so much for any input! ![]()
Hi Ksharp,
Thank you so much for your suggestion! It worked. But now I realize I need the result in a different format.
I actually need 02012 as OCT-12.
I modified your code as below and came up withAUG12. Is it possible to add a '-' between AUG and 12?
Thank you again for your help! ![]()
proc format ;
picture fmt(default=5)
other='%b%y'(datatype=date);
run;
data _null_;
a=23234;
format a fmt.;
put a= ;
run;
Try fornat nldateym8.
PG
You need customize it on your own.
proc format ; picture fmt(default=8) other='%b%Y'(datatype=date); run; data _null_; a=23234; format a fmt.; put a= ; run;
Ksharp
Hi Ksharp,
Thank you so much for your suggestion! It worked. But now I realize I need the result in a different format.
I actually need 02012 as OCT-12.
I modified your code as below and came up withAUG12. Is it possible to add a '-' between AUG and 12?
Thank you again for your help! ![]()
proc format ;
picture fmt(default=5)
other='%b%y'(datatype=date);
run;
data _null_;
a=23234;
format a fmt.;
put a= ;
run;
Hi Kevin, If you have 9.3 you could use a format based on a function. Regards Jeroen. proc fcmp outlib=work.functions.smd; function MonYear(date) $ 8; month = floor(date / 10000); year = date - (month * 10000); if month < 1 or month > 12 then do; month = 1; end; return (catx(' ', put(mdy(month, 1, year), monname3.), put(year, 4.))); endsub; run; /* Make the function available to SAS. */ options cmplib=(work.functions); /* Create a format using the function created by the FCMP procedure. */ proc format; value MonYear other=[MonYear()]; run; /* Use the format in a SAS program. */ data test; input testdate; datalines; 12011 022012 122013 ; run; proc print data=test; format testdate MonYear.; run;
Thank you, Jeroen. Unfortunately we use 9.1. Thank you for your response ![]()
Kevin
Easy.
proc format ; picture fmt(default=8) other='%b-%0y'(datatype=date); run; data _null_; a=18234; format a fmt.; put a= ; run;
Ksharp
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.