11-02-2016 03:01 PM - last edited on 11-02-2016 05:09 PM by Reeza
I am trying to use this and not getting anywhere. Any help on how to use this would be appreciated.
I am using MONTH(tbl.field_name) to pull the month out i.e.... 1, 2, 3 etc... 12
Then I was using MONNAME to get the desired result 1 = January
Here is the code that I am using now:
SELECT (MONTH(t2.Sale_Date)) LENGTH=9 LABEL="Sale_Month" AS Sale_Month,
11-02-2016 03:33 PM
11-02-2016 03:29 PM
Monname requires a date variable and I believe it's a format, not a function.
Do do you have multiple years?
Is January 2016= Jan 2015 = January?
Select date_variable format=monname.,
put(date_variable, monname.) as new month
11-02-2016 03:35 PM
MONNAME is unknown function in SAS;
There are several methods to get month name:
1) create a format like:
proc format lib=work;
1 = "January"
2 = "February"
12 = "December"
then, in your datastep use: month_name = put(month(date), monname.);
2) Alternatively use select statemnet to creat the month_name variable:
mon = month(date);
when (1) month_name = 'January';
when(2) month_name = 'February';
when (12) month_name = 'December';
otherwise month_name = 'Invalid Date';
11-02-2016 05:03 PM
You don't need to convert anything, if your variable is a SAS date.
data sample; date_var='01Nov2016'd; format date_var date9.; month_name=put(date_var, monname.); run; proc print ; run;
03-02-2018 05:53 PM
Your post helped and it could be made even simpler:
create table mytablename as
put(date_variable,monname.) as MonthNameColumn