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,
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;
What do the values of sale_date look like? Are they character or numeric?
The values need to be a SAS date value, which is numeric, in order to use the MONTH function.
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
from ....
MONNAME is unknown function in SAS;
There are several methods to get month name:
1) create a format like:
proc format lib=work;
value monname
1 = "January"
2 = "February"
...
12 = "December"
; run;
then, in your datastep use: month_name = put(month(date), monname.);
2) Alternatively use select statemnet to creat the month_name variable:
data want
set have;
mon = month(date);
select (mon);
when (1) month_name = 'January';
when(2) month_name = 'February';
...
when (12) month_name = 'December';
otherwise month_name = 'Invalid Date';
end;
run;
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;
Your post helped and it could be made even simpler:
proc sql;
create table mytablename as
select
choose_your_variables,
put(date_variable,monname.) as MonthNameColumn
from libref.table
;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.